[PATCH] D75536: [LLD] Add support for --unique option
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 11:57:47 PST 2020
MaskRay added a comment.
Do you have a plan to implement `--unique=pattern` (overrides output section descriptions)? It is different from `--unique` (only applies to orphan sections).
> The merging of these sections in the case of a partial link (-r) inhibits deadstripping.
Dead stripping is a Mach-O term. Non --unique does not inhibit --gc-sections (without -r).
Without --unique, some orphan sections may be unnecessarily kept (as a whole their "liveness" can be larger than the composing parts).
Note that -r --gc-sections is not implemented in lld.
================
Comment at: lld/ELF/LinkerScript.cpp:691
} else {
- if (OutputSection *os = addInputSec(map, s, name))
- v.push_back(os);
- assert(isa<MergeInputSection>(s) ||
- s->getOutputSection()->sectionIndex == UINT32_MAX);
+ if (OutputSection *sec = findByName(sectionCommands, name)) {
+ sec->recordSection(s);
----------------
Use `else if`
================
Comment at: lld/ELF/Options.td:378
+
+def unique: F<"unique">, HelpText<"Creates a separate output section for every orphan input section.">;
+
----------------
No period.
Add an item to `lld/docs/ld.lld.1` (manpage)
================
Comment at: lld/test/ELF/Inputs/unique-orphans.s:1
+ .text
+ .section .text.bar_2,"ax", at progbits
----------------
Delete the file.
================
Comment at: lld/test/ELF/unique-orphans.s:2
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# REQUIRES: x86
----------------
Delete `-unknown-linux`
================
Comment at: lld/test/ELF/unique-orphans.s:3
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/unique-orphans.s -o %t2.o
----------------
Keep one `REQUIRES`
================
Comment at: lld/test/ELF/unique-orphans.s:6
+
+ .text
+ .section .text.bar,"ax", at progbits
----------------
The instructions are verbose and unnecessary.
```
.section .foo,"a",unique,1
.byte 1
.section .foo,"a",unique,2
.byte 2
.section .foo,"a",unique,3
.byte 3
```
Check both `ld.lld %t.o -o %t` and `ld.lld -r %t.o -o %t.ro`
================
Comment at: lld/test/ELF/unique-orphans.s:7
+ .text
+ .section .text.bar,"ax", at progbits
+ .globl bar
----------------
Test an output section description suppresses --unique.
```
echo 'SECTIONS { .foo : { *(.foo) }}' > %t.script`
```
See `test/ELF/linkerscript/input-archive.s` for a recent example.
================
Comment at: lld/test/ELF/unique-orphans.s:25
+# RUN: ld.lld %t1.o %t2.o -r -o %t3.ro --unique
+# RUN: objdump -h %t3.ro | FileCheck --check-prefix UNIQUE %s
+# UNIQUE-COUNT-2: .text.foo
----------------
Check sections with `llvm-readelf -S`, instead of `objdump` (may not even be installed)
================
Comment at: lld/test/ELF/unique-orphans.s:29
+
+# Check that the orphan section .text.foo has been merged
+# RUN: ld.lld %t1.o %t2.o -r -o %t3.ro
----------------
Not necessary. There are plenty of tests for the non --unique case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75536/new/
https://reviews.llvm.org/D75536
More information about the llvm-commits
mailing list