зеркало из https://github.com/microsoft/clang-1.git
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
This commit is contained in:
Родитель
984f2783ad
Коммит
76e6e1377f
|
@ -282,8 +282,6 @@ def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
|
|||
HelpText<"Pass <arg> to plugin <name>">;
|
||||
def add_plugin : Separate<["-"], "add-plugin">, MetaVarName<"<name>">,
|
||||
HelpText<"Use the named plugin action in addition to the default action">;
|
||||
def resource_dir : Separate<["-"], "resource-dir">,
|
||||
HelpText<"The directory which holds the compiler resource files">;
|
||||
def version : Flag<["-"], "version">,
|
||||
HelpText<"Print the compiler version">;
|
||||
def ast_dump_filter : Separate<["-"], "ast-dump-filter">,
|
||||
|
|
|
@ -1016,6 +1016,11 @@ def rewrite_objc : Flag<["-"], "rewrite-objc">, Flags<[DriverOption,CC1Option]>,
|
|||
def rewrite_legacy_objc : Flag<["-"], "rewrite-legacy-objc">, Flags<[DriverOption]>,
|
||||
HelpText<"Rewrite Legacy Objective-C source to C++">;
|
||||
def rdynamic : Flag<["-"], "rdynamic">;
|
||||
def resource_dir : Separate<["-"], "resource-dir">,
|
||||
Flags<[DriverOption, CC1Option, HelpHidden]>,
|
||||
HelpText<"The directory which holds the compiler resource files">;
|
||||
def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[DriverOption]>,
|
||||
Alias<resource_dir>;
|
||||
def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>;
|
||||
def rtlib_EQ : Joined<["-", "--"], "rtlib=">;
|
||||
def r : Flag<["-"], "r">;
|
||||
|
|
|
@ -287,7 +287,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
|
|||
// ccc-install-dir) can change 'Dir'.
|
||||
StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
|
||||
SmallString<128> P(Dir);
|
||||
if (!ClangResourceDir.empty())
|
||||
if (const Arg *A = Args->getLastArg(options::OPT_resource_dir))
|
||||
P = A->getValue();
|
||||
else if (!ClangResourceDir.empty())
|
||||
llvm::sys::path::append(P, ClangResourceDir);
|
||||
else
|
||||
llvm::sys::path::append(P, "..", "lib", "clang", CLANG_VERSION_STRING);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -target i386-unknown-linux -fsanitize=address \
|
||||
// RUN: -resource-dir=%S/Inputs/resource_dir \
|
||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-ASAN-LINUX %s
|
||||
//
|
||||
|
@ -10,10 +11,12 @@
|
|||
// CHECK-ASAN-LINUX: libclang_rt.asan-i386.a"
|
||||
// CHECK-ASAN-LINUX: "-lpthread"
|
||||
// CHECK-ASAN-LINUX: "-ldl"
|
||||
// CHECK-ASAN-LINUX: "-export-dynamic"
|
||||
// CHECK-ASAN-LINUX-NOT: "-export-dynamic"
|
||||
// CHECK-ASAN-LINUX: "--dynamic-list={{.*}}libclang_rt.asan-i386.a.syms"
|
||||
|
||||
// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -target i386-unknown-linux -fsanitize=address \
|
||||
// RUN: -resource-dir=%S/Inputs/empty_resource_dir \
|
||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-ASAN-LINUX-CXX %s
|
||||
//
|
||||
|
@ -23,6 +26,7 @@
|
|||
// CHECK-ASAN-LINUX-CXX: "-lpthread"
|
||||
// CHECK-ASAN-LINUX-CXX: "-ldl"
|
||||
// CHECK-ASAN-LINUX-CXX: "-export-dynamic"
|
||||
// CHECK-ASAN-LINUX-CXX-NOT: "--dynamic-list"
|
||||
// CHECK-ASAN-LINUX-CXX: stdc++
|
||||
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o /dev/null -fsanitize=address \
|
||||
|
@ -58,6 +62,7 @@
|
|||
|
||||
// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -target x86_64-unknown-linux -lstdc++ -fsanitize=thread \
|
||||
// RUN: -resource-dir=%S/Inputs/resource_dir \
|
||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-TSAN-LINUX-CXX %s
|
||||
//
|
||||
|
@ -66,11 +71,13 @@
|
|||
// CHECK-TSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.tsan-x86_64.a" "-no-whole-archive"
|
||||
// CHECK-TSAN-LINUX-CXX: "-lpthread"
|
||||
// CHECK-TSAN-LINUX-CXX: "-ldl"
|
||||
// CHECK-TSAN-LINUX-CXX: "-export-dynamic"
|
||||
// CHECK-TSAN-LINUX-CXX-NOT: "-export-dynamic"
|
||||
// CHECK-TSAN-LINUX-CXX: "--dynamic-list={{.*}}libclang_rt.tsan-x86_64.a.syms"
|
||||
// CHECK-TSAN-LINUX-CXX: stdc++
|
||||
|
||||
// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -target x86_64-unknown-linux -lstdc++ -fsanitize=memory \
|
||||
// RUN: -resource-dir=%S/Inputs/resource_dir \
|
||||
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-MSAN-LINUX-CXX %s
|
||||
//
|
||||
|
@ -79,7 +86,8 @@
|
|||
// CHECK-MSAN-LINUX-CXX: "-whole-archive" "{{.*}}libclang_rt.msan-x86_64.a" "-no-whole-archive"
|
||||
// CHECK-MSAN-LINUX-CXX: "-lpthread"
|
||||
// CHECK-MSAN-LINUX-CXX: "-ldl"
|
||||
// CHECK-MSAN-LINUX-CXX: "-export-dynamic"
|
||||
// CHECK-MSAN-LINUX-CXX-NOT: "-export-dynamic"
|
||||
// CHECK-MSAN-LINUX-CXX: "--dynamic-list={{.*}}libclang_rt.msan-x86_64.a.syms"
|
||||
// CHECK-MSAN-LINUX-CXX: stdc++
|
||||
|
||||
// RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \
|
||||
|
|
Загрузка…
Ссылка в новой задаче