[PATCH] D75536: [LLD] Add support for --unique option
Dave Bozier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 15:00:37 PST 2020
davidb updated this revision to Diff 248045.
davidb added a comment.
- review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75536/new/
https://reviews.llvm.org/D75536
Files:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/Options.td
lld/test/ELF/unique-orphans.s
Index: lld/test/ELF/unique-orphans.s
===================================================================
--- /dev/null
+++ lld/test/ELF/unique-orphans.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+.section .foo,"a", at progbits,unique,1
+.byte 1
+
+.section .foo,"a", at progbits,unique,2
+.byte 2
+
+.section .foo,"a", at progbits,unique,3
+.byte 3
+
+# We should have 2 instance of orphan section .text.foo
+# RUN: ld.lld %t.o -r -o %t.ro --unique
+# RUN: llvm-objdump -h %t.ro | FileCheck --check-prefix UNIQUE_R %s
+# UNIQUE_R-COUNT-3: .foo
+# UNIQUE_R-NOT: .foo
+
+# We should have 2 instance of orphan section .text.foo
+# RUN: ld.lld %t.o -o %t.elf --unique
+# RUN: llvm-objdump -h %t.elf | FileCheck --check-prefix UNIQUE %s
+# UNIQUE-COUNT-3: .foo
+# UNIQUE-NOT: .foo
+
+# RUN: echo 'SECTIONS { .foo : { *(.foo) }}' > %t.script
+# RUN: ld.lld %t.o -o %t2.elf -T %t.script --unique
+# RUN: llvm-objdump -h %t2.elf | FileCheck --check-prefix UNIQUE_SCRIPT %s
+# UNIQUE_SCRIPT: .foo
+# UNIQUE_SCRIPT-NOT: .foo
\ No newline at end of file
Index: lld/ELF/Options.td
===================================================================
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -374,6 +374,9 @@
defm undefined_glob: Eq<"undefined-glob", "Force undefined symbol during linking">,
MetaVarName<"<pattern>">;
+
+def unique: F<"unique">, HelpText<"Creates a separate output section for every orphan input section">;
+
defm unresolved_symbols:
Eq<"unresolved-symbols", "Determine how to handle unresolved symbols">;
Index: lld/ELF/LinkerScript.cpp
===================================================================
--- lld/ELF/LinkerScript.cpp
+++ lld/ELF/LinkerScript.cpp
@@ -684,7 +684,10 @@
orphanSections.push_back(s);
StringRef name = getOutputSectionName(s);
- if (OutputSection *sec = findByName(sectionCommands, name)) {
+
+ if (config->unique) {
+ v.push_back(createSection(s, name));
+ } else if (OutputSection *sec = findByName(sectionCommands, name)) {
sec->recordSection(s);
} else {
if (OutputSection *os = addInputSec(map, s, name))
@@ -693,6 +696,7 @@
s->getOutputSection()->sectionIndex == UINT32_MAX);
}
}
+ }
if (config->relocatable)
for (InputSectionBase *depSec : s->dependentSections)
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -967,6 +967,7 @@
config->splitStackAdjustSize = args::getInteger(args, OPT_split_stack_adjust_size, 16384);
config->strip = getStrip(args);
config->sysroot = args.getLastArgValue(OPT_sysroot);
+ config->unique = args.hasArg(OPT_unique);
config->target1Rel = args.hasFlag(OPT_target1_rel, OPT_target1_abs, false);
config->target2 = getTarget2(args);
config->thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -194,6 +194,7 @@
bool timeTraceEnabled;
bool tocOptimize;
bool undefinedVersion;
+ bool unique = false;
bool useAndroidRelrTags = false;
bool warnBackrefs;
bool warnCommon;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75536.248045.patch
Type: text/x-patch
Size: 3298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/d08d4b73/attachment.bin>
More information about the llvm-commits
mailing list