[all-commits] [llvm/llvm-project] 775a94: [IR][sanitizer] Set nounwind on module ctor/dtor, ...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Wed Apr 21 15:58:40 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 775a9483e55efb365691bc425ed107568ad6daf8
https://github.com/llvm/llvm-project/commit/775a9483e55efb365691bc425ed107568ad6daf8
Author: Fangrui Song <i at maskray.me>
Date: 2021-04-21 (Wed, 21 Apr 2021)
Changed paths:
M clang/lib/CodeGen/CodeGenModule.cpp
M clang/test/CodeGen/asan-globals.cpp
M clang/test/CodeGen/asan-new-pm.ll
M clang/test/CodeGen/asan-no-globals-no-comdat.cpp
M llvm/include/llvm/IR/Function.h
M llvm/include/llvm/IR/Module.h
M llvm/lib/IR/Function.cpp
M llvm/lib/IR/Module.cpp
M llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
M llvm/lib/Transforms/Utils/ModuleUtils.cpp
M llvm/test/Instrumentation/AddressSanitizer/basic.ll
M llvm/test/Instrumentation/AddressSanitizer/no-globals.ll
A llvm/test/Instrumentation/AddressSanitizer/uwtable.ll
M llvm/test/Instrumentation/HWAddressSanitizer/basic.ll
M llvm/test/Instrumentation/HWAddressSanitizer/with-calls.ll
M llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll
M llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-8bit-counters.ll
M llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard-inline-bool-flag.ll
M llvm/test/Instrumentation/SanitizerCoverage/trace-pc-guard.ll
Log Message:
-----------
[IR][sanitizer] Set nounwind on module ctor/dtor, additionally set uwtable if -fasynchronous-unwind-tables
On ELF targets, if a function has uwtable or personality, or does not have
nounwind (`needsUnwindTableEntry`), it marks that `.eh_frame` is needed in the module.
Then, a function gets `.eh_frame` if `needsUnwindTableEntry` or `-g[123]` is specified.
(i.e. If -g[123], every function gets `.eh_frame`.
This behavior is strange but that is the status quo on GCC and Clang.)
Let's take asan as an example. Other sanitizers are similar.
`asan.module_[cd]tor` has no attribute. `needsUnwindTableEntry` returns true,
so every function gets `.eh_frame` if `-g[123]` is specified.
This is the root cause that
`-fno-exceptions -fno-asynchronous-unwind-tables -g` produces .debug_frame
while
`-fno-exceptions -fno-asynchronous-unwind-tables -g -fsanitize=address` produces .eh_frame.
This patch
* sets the nounwind attribute on sanitizer module ctor/dtor.
* let Clang emit a module flag metadata "uwtable" for -fasynchronous-unwind-tables. If "uwtable" is set, sanitizer module ctor/dtor additionally get the uwtable attribute.
The "uwtable" mechanism is generic: synthesized functions not cloned/specialized
from existing ones should consider `Function::createWithDefaultAttr` instead of
`Function::create` if they want to get some default attributes which
have more of module semantics.
Other candidates: "frame-pointer" (https://github.com/ClangBuiltLinux/linux/issues/955
https://github.com/ClangBuiltLinux/linux/issues/1238), dso_local, etc.
Differential Revision: https://reviews.llvm.org/D100251
More information about the All-commits
mailing list