[all-commits] [llvm/llvm-project] 4e572d: [lld/mac] Mark private externs with GOT relocs as ...
Nico Weber via All-commits
all-commits at lists.llvm.org
Fri Oct 15 10:25:01 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 4e572db0c2ec4e96f8ddfade7384e8ee8ad97384
https://github.com/llvm/llvm-project/commit/4e572db0c2ec4e96f8ddfade7384e8ee8ad97384
Author: Nico Weber <thakis at chromium.org>
Date: 2021-10-15 (Fri, 15 Oct 2021)
Changed paths:
M lld/MachO/SyntheticSections.cpp
M lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
M lld/test/MachO/indirect-symtab.s
Log Message:
-----------
[lld/mac] Mark private externs with GOT relocs as LOCAL in indirect symbtab
prepareSymbolRelocation() in Writer.cpp adds both symbols that need binding and
symbols relocated with a pointer relocation to the got.
Pointer relocations are emitted for non-movq GOTPCREL(%rip) loads. (movqs
become GOT_LOADs so that the linker knows they can be relaxed to leaqs, while
others, such as addq, become just GOT -- a pointer relocation -- since they
can't be relaxed in that way).
For example, this C file produces a private_extern GOT relocation when
compiled with -O2 with clang:
extern const char kString[];
const char* g(int a) { return kString + a; }
Linkers need to put pointer-relocated symbols into the GOT, but ld64 marks them
as LOCAL in the indirect symbol table. This matters, since `strip -x` looks at
the indirect symbol table when deciding what to strip.
The indirect symtab emitting code was assuming that only symbols that need
binding are in the GOT, but pointer relocations where there too. Hence, the
code needs to explicitly check if a symbol is a private extern.
Fixes https://crbug.com/1242638, which has some more information in comments 14
and 15. With this patch, the output of `nm -U` on Chromium Framework after
stripping now contains just two symbols when using lld, just like with ld64.
Differential Revision: https://reviews.llvm.org/D111852
More information about the All-commits
mailing list