[PATCH] D93609: [lld/mac] Implement support for private extern symbols

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 20 20:24:01 PST 2020


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a subscriber: dang.
thakis requested review of this revision.

Private extern symbols are used for things scoped to the linkage unit.
They cause duplicate symbol errors (so they're in the symbol table,
unlike TU-scoped truly local symbols), but they don't make it into the
export trie. They are created e.g. by compiling with
-fvisibility=hidden.

If two weak symbols have differing privateness, the combined symbol is
non-private external. (Example: inline functions and some TUs that
include the header defining it were built with
-fvisibility-inlines-hidden and some weren't).

A weak private external symbol implicitly has its "weak" dropped and
behaves like a regular strong private external symbol: Weak is an export
trie concept, and private symbols are not in the export trie.

If a weak and a strong symbol have different privateness, the strong
symbol wins.

If two common symbols have differing privateness, the larger symbol
wins. If they have the same size, the combined symbol is non-private
external. (Example: `int a` in two .c files, both built with -fcommon,
one built with -fvisibility=hidden and one without.)

This also makes __dyld_private a true TU-local symbol, matching ld64.
To make this work, make the `const char*` StringRefZ ctor to correctly
set `size` (without this, writing the string table crashed when calling
getName() on the __dyld_private symbol).

Mention in CommonSymbol's comment that common symbols are now disabled
by default in clang.

Mention in -keep_private_externs's HelpText that the flag only has an
effect with `-r` (which we don't implement yet -- so this patch here
doesn't regress any behavior around -r + -keep_private_externs)). ld64
doesn't explicitly document it, but the commit text of
http://reviews.llvm.org/rL216146 does, and ld64's
OutputFile::buildSymbolTable() checks `_options.outputKind() ==
Options::kObjectFile` before calling `_options.keepPrivateExterns()`
(the only reference to that function).

Fixes PR48536.

-

This is not 100% complete. It's missing a bunch of tests (see XXXs in the new private-extern.s), and there's a bunch of XXXs around weak private externs in SyntheticSections.cpp where I need to figure out what the behavior should be. But most of the patch is done, so I'm sending it out for early feedback.


https://reviews.llvm.org/D93609

Files:
  lld/MachO/Driver.cpp
  lld/MachO/InputFiles.cpp
  lld/MachO/Options.td
  lld/MachO/SymbolTable.cpp
  lld/MachO/SymbolTable.h
  lld/MachO/Symbols.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/SyntheticSections.h
  lld/test/MachO/dylink-lazy.s
  lld/test/MachO/private-extern.s
  lld/test/MachO/symtab.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93609.313016.patch
Type: text/x-patch
Size: 18300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201221/23b22b8f/attachment.bin>


More information about the llvm-commits mailing list