[PATCH] D75536: [LLD] Add support for --unique option

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 05:49:34 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6e2804ce6baa: [LLD] Add support for --unique option (authored by David Bozier <daveb at graphcore.ai>).

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/docs/ld.lld.1
  lld/test/ELF/unique-orphans.s


Index: lld/test/ELF/unique-orphans.s
===================================================================
--- /dev/null
+++ lld/test/ELF/unique-orphans.s
@@ -0,0 +1,26 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %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 3 instances of orphan section foo.
+## Test with -r
+# RUN: ld.lld %t.o -o %t.elf --unique 
+# RUN: llvm-readelf -S %t.elf | FileCheck %s
+
+# CHECK-COUNT-3: .foo
+# CHECK-NOT: .foo
+
+## Test that --unique does not affect sections specified in output section descriptions.
+# RUN: echo 'SECTIONS { .foo : { *(.foo) }}' > %t.script
+# RUN: ld.lld %t.o -o %t2.elf -T %t.script --unique 
+# RUN: llvm-readelf -S %t2.elf | FileCheck --check-prefix SCRIPT %s
+# SCRIPT: .foo
+# SCRIPT-NOT: .foo
Index: lld/docs/ld.lld.1
===================================================================
--- lld/docs/ld.lld.1
+++ lld/docs/ld.lld.1
@@ -553,6 +553,8 @@
 All symbols that match
 a given pattern are handled as if they were given as arguments of
 .Fl -undefined .
+.It Fl -unique
+Creates a separate output section for every orphan input section.
 .It Fl -unresolved-symbols Ns = Ns Ar value
 Determine how to handle unresolved symbols.
 .It Fl -use-android-relr-tags
Index: lld/ELF/Options.td
===================================================================
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -374,6 +374,8 @@
 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
@@ -685,7 +685,9 @@
       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))
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -986,6 +986,7 @@
   config->undefined = args::getStrings(args, OPT_undefined);
   config->undefinedVersion =
       args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, true);
+  config->unique = args.hasArg(OPT_unique);
   config->useAndroidRelrTags = args.hasFlag(
       OPT_use_android_relr_tags, OPT_no_use_android_relr_tags, false);
   config->unresolvedSymbols = getUnresolvedSymbolPolicy(args);
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;
   bool useAndroidRelrTags = false;
   bool warnBackrefs;
   bool warnCommon;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75536.249335.patch
Type: text/x-patch
Size: 3326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200310/432c0fa5/attachment.bin>


More information about the llvm-commits mailing list