Skip to content

Commit

Permalink
Build libsanitizer_common_rt with -Wno-format
Browse files Browse the repository at this point in the history
Many lines that call `InternalScopedString::AppendF`, including the
below,
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp#L31
are format-checked by
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/compiler-rt/lib/sanitizer_common/sanitizer_common.h#L650
which checks if the formats of arguments conform to that of functions
like `printf`. But this errors out because the format strings currently
do not match their arguments.

llvm/llvm-project@9c8f888#diff-5bf0494d1b61b99e55aefb25e59e41b678f20a392c2c6d77e5fbdc97c2ca4c3f
started the effort to check `__attribute__((format))` in the codebase,
but apparently there were too many violating instances, it made the code
build with `-Wno-format` (presumably as an temporary solution):
https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/compiler-rt/lib/sanitizer_common/CMakeLists.txt#L223-L224
So this adds `-Wno-format` to our cflags as well.

The reason it was fine without it until now is, we didn't build the
whole file thanks to this line:
https://github.com/emscripten-core/emscripten/blob/a9b347bfcabda59a5edff60ee18b8a0ab70aa9dc/system/lib/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp#L15

But recent refactoring efforts including
llvm/llvm-project#73032,
llvm/llvm-project#73192, and
llvm/llvm-project#73193 moved many parts out of
that file to be built by a specific platform (e.g. fushia) and made the
file build unconditionally. I tried to add back `#if
SANITIZER_SYMBOLIZER_MARKUP` to that file but then this line
(https://github.com/llvm/llvm-project/blob/26a1d6601d727a96f4301d0d8647b5a42760ae0c/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp#L67)
breaks with an undefined referenc error. So just build the library with
`-Wno-format`, which is also what the upstream is effectively doing,
seems a simpler solution.
  • Loading branch information
aheejin committed Apr 7, 2024
1 parent 9272ada commit 67108b2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ class libsanitizer_common_rt(CompilerRTLibrary, MTLibrary):
'system/lib/compiler-rt/lib',
'system/lib/libc']
never_force = True
cflags = ['-D_LARGEFILE64_SOURCE']
cflags = ['-D_LARGEFILE64_SOURCE', '-Wno-format']

src_dir = 'system/lib/compiler-rt/lib/sanitizer_common'
src_glob = '*.cpp'
Expand Down

0 comments on commit 67108b2

Please sign in to comment.