[PATCH] D137227: [asan] Default to -fsanitize-address-use-odr-indicator

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 22:34:30 PDT 2022


MaskRay created this revision.
MaskRay added reviewers: Sanitizers, eugenis, kcc, kstoimenov, vitalybuka.
Herald added subscribers: Enna1, StephenFan, sunfish, hiraditya, dschuff.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, Sanitizers, LLVM.

This enables odr indicators on all platforms and private aliases on
ELF/Mach-O/WebAssembly platforms (Windows does not use private alias).
Note that GCC also uses private aliases.

Bogus `The following global variable is not properly aligned.` error for
interposed global variables is fixed.
(PR37545 (this patch should allow us to restore D46665 <https://reviews.llvm.org/D46665>) and https://github.com/google/sanitizers/issues/1017)

Global variables of non-hasExactDefinition() linkages (i.e.
linkonce/linkonce_odr/weak/weak_odr/common/external_weak) are not instrumented.
If an instrumented variable gets interposed to an uninstrumented variable due to
symbol interposition (e.g. in PR37545, _ZTS1A in foo.so is resolved to _ZTS1A in
the executable), there may be a bogus error.

With private aliases, the register code will not resolve to a definition in
another module, and thus prevent the issue.

https://github.com/google/sanitizers/issues/398 Similar to the above, but about
an instrumented global variable gets interposed to an uninstrumented global
variable (not using address sanitizer) in another module.

Cons: negligible size increase. On ELF, this is mainly due to extra `__odr_asan_gen_*` symbols.
In relocatable files, private aliases replace some relocations referencing
global symbols with .L symbols. This may introduce some STT_SECTION symbols.

For lld, with -g0, the size increase is 0.07~0.09% for many configurations I
have tested: -O0, -O1, -O2, -O3, -O2 -ffunction-sections -fdata-sections
-Wl,--gc-sections. With -g1 or above, the size increase ratio will be even smaller.

This replaces D92078 <https://reviews.llvm.org/D92078>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137227

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/asan-globals-odr.cpp
  clang/test/CodeGen/asan-static-odr.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/test/asan/TestCases/Linux/odr-violation.cpp
  compiler-rt/test/asan/TestCases/Linux/odr_indicators.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137227.472507.patch
Type: text/x-patch
Size: 14211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221102/b73c2ce4/attachment.bin>


More information about the llvm-commits mailing list