Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Sanitize for undefined behavior #4845

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
mkdir build
cd build
make -f ../Makefile config-$CC
echo 'SANITIZER = undefined' >> Makefile.conf
make -f ../Makefile -j$procs ENABLE_LTO=1

- name: Log yosys-config output
Expand All @@ -82,6 +83,7 @@ jobs:
if: needs.pre_job.outputs.should_skip != 'true'
env:
CC: clang
UBSAN_OPTIONS: halt_on_error=1
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand Down
42 changes: 42 additions & 0 deletions libs/fst/00_PATCH_strict_alignment.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
diff --git a/fastlz.cc b/fastlz.cc
index 3272ca7a8..41ea27a16 100644
--- a/fastlz.cc
+++ b/fastlz.cc
@@ -60,24 +60,9 @@
#endif

/*
- * Prevent accessing more than 8-bit at once, except on x86 architectures.
+ * Yosys patch: do not do unaligned accesses on any platform
*/
-#if !defined(FASTLZ_STRICT_ALIGN)
#define FASTLZ_STRICT_ALIGN
-#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__amd64) /* GNU C */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_M_IX86) /* Intel, MSVC */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__386)
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(_X86_) /* MinGW */
-#undef FASTLZ_STRICT_ALIGN
-#elif defined(__I86__) /* Digital Mars */
-#undef FASTLZ_STRICT_ALIGN
-#endif
-#endif

/* prototypes */
int fastlz_compress(const void* input, int length, void* output);
@@ -88,11 +73,7 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
#define MAX_LEN 264 /* 256 + 8 */
#define MAX_DISTANCE 8192

-#if !defined(FASTLZ_STRICT_ALIGN)
-#define FASTLZ_READU16(p) *((const flzuint16*)(p))
-#else
#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8)
-#endif

#define HASH_LOG 13
#define HASH_SIZE (1<< HASH_LOG)
1 change: 1 addition & 0 deletions libs/fst/00_UPDATE.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ sed -i -e 's,"fastlz.c","fastlz.cc",' *.cc *.h

patch -p0 < 00_PATCH_win_zlib.patch
patch -p0 < 00_PATCH_win_io.patch
patch -p1 < 00_PATCH_strict_alignment.patch
21 changes: 1 addition & 20 deletions libs/fst/fastlz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,9 @@
#endif

/*
* Prevent accessing more than 8-bit at once, except on x86 architectures.
* Yosys patch: do not do unaligned accesses on any platform
*/
#if !defined(FASTLZ_STRICT_ALIGN)
#define FASTLZ_STRICT_ALIGN
#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */
#undef FASTLZ_STRICT_ALIGN
#elif defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__amd64) /* GNU C */
#undef FASTLZ_STRICT_ALIGN
#elif defined(_M_IX86) /* Intel, MSVC */
#undef FASTLZ_STRICT_ALIGN
#elif defined(__386)
#undef FASTLZ_STRICT_ALIGN
#elif defined(_X86_) /* MinGW */
#undef FASTLZ_STRICT_ALIGN
#elif defined(__I86__) /* Digital Mars */
#undef FASTLZ_STRICT_ALIGN
#endif
#endif

/* prototypes */
int fastlz_compress(const void* input, int length, void* output);
Expand All @@ -88,11 +73,7 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
#define MAX_LEN 264 /* 256 + 8 */
#define MAX_DISTANCE 8192

#if !defined(FASTLZ_STRICT_ALIGN)
#define FASTLZ_READU16(p) *((const flzuint16*)(p))
#else
#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8)
#endif

#define HASH_LOG 13
#define HASH_SIZE (1<< HASH_LOG)
Expand Down
Loading