diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-23 00:30:08 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-03-23 00:30:08 +0000 |
commit | 76e6e1377ff837047fb8e03a199c7f286c53897b (patch) | |
tree | b92060a34a05a42069c381376162f3864e987878 /lib/Driver/Tools.cpp | |
parent | 984f2783ad8319aa0cbfca1c4a719688b1ecfd5e (diff) |
If a .syms file is available alongside a sanitizer runtime, pass it to the
linker via --dynamic-list instead of using --export-dynamic. This reduces the
size of the dynamic symbol table, and thus of the binary (in some cases by up
to ~30%).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r-- | lib/Driver/Tools.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index cb84e0a547..2581ae36f7 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1575,7 +1575,8 @@ SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) static void addSanitizerRTLinkFlagsLinux( const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, - const StringRef Sanitizer, bool BeforeLibStdCXX) { + const StringRef Sanitizer, bool BeforeLibStdCXX, + bool ExportSymbols = true) { // Sanitizer runtime is located in the Linux library directory and // has name "libclang_rt.<Sanitizer>-<ArchName>.a". SmallString<128> LibSanitizer(TC.getDriver().ResourceDir); @@ -1599,7 +1600,17 @@ static void addSanitizerRTLinkFlagsLinux( CmdArgs.push_back("-lpthread"); CmdArgs.push_back("-ldl"); - CmdArgs.push_back("-export-dynamic"); + + // If possible, use a dynamic symbols file to export the symbols from the + // runtime library. If we can't do so, use -export-dynamic instead to export + // all symbols from the binary. + if (ExportSymbols) { + if (llvm::sys::fs::exists(LibSanitizer + ".syms")) + CmdArgs.push_back( + Args.MakeArgString("--dynamic-list=" + LibSanitizer + ".syms")); + else + CmdArgs.push_back("-export-dynamic"); + } } /// If AddressSanitizer is enabled, add appropriate linker flags (Linux). @@ -1666,7 +1677,7 @@ static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args, // Need a copy of sanitizer_common. This could come from another sanitizer // runtime; if we're not including one, include our own copy. if (!HasOtherSanitizerRt) - addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "san", true); + addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "san", true, false); addSanitizerRTLinkFlagsLinux(TC, Args, CmdArgs, "ubsan", false); |