[lld] 1d1aa2d - [lld-macho] Mark aliased symbols as noDeadStrip
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 14:54:35 PDT 2022
Author: Keith Smiley
Date: 2022-10-04T14:53:53-07:00
New Revision: 1d1aa2d0130ce5683514330c876464bfd754dec3
URL: https://github.com/llvm/llvm-project/commit/1d1aa2d0130ce5683514330c876464bfd754dec3
DIFF: https://github.com/llvm/llvm-project/commit/1d1aa2d0130ce5683514330c876464bfd754dec3.diff
LOG: [lld-macho] Mark aliased symbols as noDeadStrip
This matches ld64 behavior
Differential Revision: https://reviews.llvm.org/D135082
Added:
Modified:
lld/MachO/Driver.cpp
lld/MachO/MarkLive.cpp
lld/test/MachO/alias-option.s
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index febeace99d3a..a1a491c4a819 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1241,7 +1241,8 @@ static void createAliases() {
for (const auto &pair : config->aliasedSymbols) {
if (const auto &sym = symtab->find(pair.first)) {
if (const auto &defined = dyn_cast<Defined>(sym)) {
- symtab->aliasDefined(defined, pair.second, defined->getFile());
+ symtab->aliasDefined(defined, pair.second, defined->getFile())
+ ->noDeadStrip = true;
} else {
error("TODO: support aliasing to symbols of kind " +
Twine(sym->kind()));
diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp
index d407599ee810..2ad85c62d047 100644
--- a/lld/MachO/MarkLive.cpp
+++ b/lld/MachO/MarkLive.cpp
@@ -229,7 +229,7 @@ void markLive() {
// FIXME: When we implement these flags, make symbols from them GC
// roots:
// * -reexported_symbol(s_list)
- // * -alias(-list)
+ // * -alias_list
// * -init
// In dylibs and bundles and in executables with -export_dynamic,
diff --git a/lld/test/MachO/alias-option.s b/lld/test/MachO/alias-option.s
index dd366e78bc5f..087a5e021b8f 100644
--- a/lld/test/MachO/alias-option.s
+++ b/lld/test/MachO/alias-option.s
@@ -21,7 +21,9 @@
# MAIN: [[#%x,FOO_ADDR:]] T _foo
# MAIN: [[#FOO_ADDR]] T _main
-# RUN: %lld -alias _foo _bar -alias _main _fake_main %t/main.o %t/foo.o -o %t/multiple.o
+## Verify dead stripping doesn't remove the aliased symbol. This behavior
diff ers
+## from ld64 where it actually does dead strip only the alias, not the original symbol.
+# RUN: %lld -dead_strip -alias _foo _bar -alias _main _fake_main %t/main.o %t/foo.o -o %t/multiple.o
# RUN: llvm-nm %t/multiple.o | FileCheck %s --check-prefix=MULTIPLE
# MULTIPLE: [[#%x,FOO_ADDR:]] T _bar
@@ -30,11 +32,13 @@
# MULTIPLE: [[#MAIN_ADDR]] T _main
#--- foo.s
+.subsections_via_symbols
.globl _foo
_foo:
ret
#--- main.s
+.subsections_via_symbols
.globl _main
_main:
ret
More information about the llvm-commits
mailing list