aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-11-04 14:42:21 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-11-04 14:42:21 +0000
commitd08c35566595bf29a50e39cbaaf32188ede63f7a (patch)
tree8e0d582dbfb68a3bf01decdab787004fde19f3de
parentebe7d41024f3c7f5adddb6a1ff1d0d3361f58c1c (diff)
downloadsrc-vendor/lld-70.tar.gz
src-vendor/lld-70.zip
Notes
Notes: svn path=/vendor/lld/dist-release_70/; revision=340122 svn path=/vendor/lld/lld-release_701-r349250/; revision=342121; tag=vendor/lld/lld-release_701-r349250
-rw-r--r--COFF/Chunks.h4
-rw-r--r--ELF/ScriptParser.cpp18
-rw-r--r--ELF/Symbols.cpp2
-rw-r--r--ELF/Writer.cpp2
-rw-r--r--test/COFF/arm64-localimport-align.s24
-rw-r--r--test/ELF/linkerscript/memory-include.test23
-rw-r--r--test/ELF/linkerscript/output-section-include.test30
-rw-r--r--test/ELF/linkerscript/section-include.test32
-rw-r--r--test/ELF/local-ver-preemptible.s22
-rw-r--r--test/ELF/relocatable-rel-iplt.s56
10 files changed, 205 insertions, 8 deletions
diff --git a/COFF/Chunks.h b/COFF/Chunks.h
index 9e896531bd9a..b3199d8d603c 100644
--- a/COFF/Chunks.h
+++ b/COFF/Chunks.h
@@ -345,7 +345,9 @@ private:
// See comments for DefinedLocalImport class.
class LocalImportChunk : public Chunk {
public:
- explicit LocalImportChunk(Defined *S) : Sym(S) {}
+ explicit LocalImportChunk(Defined *S) : Sym(S) {
+ Alignment = Config->is64() ? 8 : 4;
+ }
size_t getSize() const override;
void getBaserels(std::vector<Baserel> *Res) override;
void writeTo(uint8_t *Buf) const override;
diff --git a/ELF/ScriptParser.cpp b/ELF/ScriptParser.cpp
index ddb4a49a3e5e..62fde7199754 100644
--- a/ELF/ScriptParser.cpp
+++ b/ELF/ScriptParser.cpp
@@ -497,6 +497,9 @@ void ScriptParser::readSections() {
for (BaseCommand *Cmd : readOverlay())
V.push_back(Cmd);
continue;
+ } else if (Tok == "INCLUDE") {
+ readInclude();
+ continue;
}
if (BaseCommand *Cmd = readAssignment(Tok))
@@ -778,6 +781,8 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef OutSec) {
Cmd->Filler = readFill();
} else if (Tok == "SORT") {
readSort();
+ } else if (Tok == "INCLUDE") {
+ readInclude();
} else if (peek() == "(") {
Cmd->SectionCommands.push_back(readInputSectionDescription(Tok));
} else {
@@ -1404,7 +1409,11 @@ uint64_t ScriptParser::readMemoryAssignment(StringRef S1, StringRef S2,
void ScriptParser::readMemory() {
expect("{");
while (!errorCount() && !consume("}")) {
- StringRef Name = next();
+ StringRef Tok = next();
+ if (Tok == "INCLUDE") {
+ readInclude();
+ continue;
+ }
uint32_t Flags = 0;
uint32_t NegFlags = 0;
@@ -1419,10 +1428,9 @@ void ScriptParser::readMemory() {
uint64_t Length = readMemoryAssignment("LENGTH", "len", "l");
// Add the memory region to the region map.
- MemoryRegion *MR =
- make<MemoryRegion>(Name, Origin, Length, Flags, NegFlags);
- if (!Script->MemoryRegions.insert({Name, MR}).second)
- setError("region '" + Name + "' already defined");
+ MemoryRegion *MR = make<MemoryRegion>(Tok, Origin, Length, Flags, NegFlags);
+ if (!Script->MemoryRegions.insert({Tok, MR}).second)
+ setError("region '" + Tok + "' already defined");
}
}
diff --git a/ELF/Symbols.cpp b/ELF/Symbols.cpp
index 4243cb1e80ef..f312de71c82c 100644
--- a/ELF/Symbols.cpp
+++ b/ELF/Symbols.cpp
@@ -209,7 +209,7 @@ uint8_t Symbol::computeBinding() const {
return Binding;
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
return STB_LOCAL;
- if (VersionId == VER_NDX_LOCAL && isDefined())
+ if (VersionId == VER_NDX_LOCAL && isDefined() && !IsPreemptible)
return STB_LOCAL;
if (!Config->GnuUnique && Binding == STB_GNU_UNIQUE)
return STB_GLOBAL;
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index 88a2d5c71266..09a17049ffb4 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -874,7 +874,7 @@ void PhdrEntry::add(OutputSection *Sec) {
// need these symbols, since IRELATIVE relocs are resolved through GOT
// and PLT. For details, see http://www.airs.com/blog/archives/403.
template <class ELFT> void Writer<ELFT>::addRelIpltSymbols() {
- if (needsInterpSection())
+ if (Config->Relocatable || needsInterpSection())
return;
StringRef S = Config->IsRela ? "__rela_iplt_start" : "__rel_iplt_start";
addOptionalRegular(S, InX::RelaIplt, 0, STV_HIDDEN, STB_WEAK);
diff --git a/test/COFF/arm64-localimport-align.s b/test/COFF/arm64-localimport-align.s
new file mode 100644
index 000000000000..4fbc79ec36d7
--- /dev/null
+++ b/test/COFF/arm64-localimport-align.s
@@ -0,0 +1,24 @@
+// REQUIRES: aarch64
+// RUN: llvm-mc -filetype=obj -triple=aarch64-windows %s -o %t.obj
+// RUN: lld-link -entry:main -subsystem:console %t.obj -out:%t.exe
+// Don't check the output, just make sure it links fine and doesn't
+// error out due to a misaligned load.
+ .text
+ .globl main
+ .globl myfunc
+main:
+ adrp x8, __imp_myfunc
+ ldr x0, [x8, :lo12:__imp_myfunc]
+ br x0
+ ret
+myfunc:
+ ret
+
+ .section .rdata, "dr"
+ // Start the .rdata section with a 4 byte chunk, to expose the alignment
+ // of the next chunk in the section.
+mydata:
+ .byte 42
+ // The synthesized LocalImportChunk gets stored here in the .rdata
+ // section, but needs to get proper 8 byte alignment since it is a
+ // pointer, just like regular LookupChunks in the IAT.
diff --git a/test/ELF/linkerscript/memory-include.test b/test/ELF/linkerscript/memory-include.test
new file mode 100644
index 000000000000..340328225bde
--- /dev/null
+++ b/test/ELF/linkerscript/memory-include.test
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+# RUN: echo "RAM2 (rwx): ORIGIN = 0x3000, LENGTH = 0x100" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s
+# CHECK: .data 00000008 0000000000002000 DATA
+# CHECK: .data2 00000008 0000000000003000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+ INCLUDE "memory-include.test.tmp.inc"
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ .data2 : { QUAD(0) } > RAM2
+}
diff --git a/test/ELF/linkerscript/output-section-include.test b/test/ELF/linkerscript/output-section-include.test
new file mode 100644
index 000000000000..b18a7ee037a3
--- /dev/null
+++ b/test/ELF/linkerscript/output-section-include.test
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+
+## Non-empty include file.
+# RUN: echo "QUAD(0)" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000010 0000000000002000 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : {
+ *(.data*)
+ INCLUDE "output-section-include.test.tmp.inc"
+ } > RAM
+}
diff --git a/test/ELF/linkerscript/section-include.test b/test/ELF/linkerscript/section-include.test
new file mode 100644
index 000000000000..9b6dfa0dcc4e
--- /dev/null
+++ b/test/ELF/linkerscript/section-include.test
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+
+# RUN: echo '.section .text,"ax"; .global _start; nop' > %t.s
+# RUN: echo '.section .data,"aw"; .quad 0' >> %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+
+## Empty include file.
+# RUN: echo "" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK1
+# CHECK1: .data 00000008 0000000000002000 DATA
+# CHECK1-NEXT: .data3 00000008 0000000000002008 DATA
+
+## Non-empty include file.
+# RUN: echo ".data2 : { QUAD(0) } > RAM" > %t.inc
+# RUN: ld.lld -o %t.elf --script %s %t.o -L %T
+# RUN: llvm-objdump -section-headers %t.elf | FileCheck %s --check-prefix=CHECK2
+# CHECK2: .data 00000008 0000000000002000 DATA
+# CHECK2-NEXT: .data2 00000008 0000000000002008 DATA
+# CHECK2-NEXT: .data3 00000008 0000000000002010 DATA
+
+MEMORY {
+ ROM (rwx): ORIGIN = 0x1000, LENGTH = 0x100
+ RAM (rwx): ORIGIN = 0x2000, LENGTH = 0x100
+}
+
+SECTIONS {
+ .text : { *(.text*) } > ROM
+ .data : { *(.data*) } > RAM
+ INCLUDE "section-include.test.tmp.inc"
+ .data3 : { QUAD(0) } > RAM
+}
diff --git a/test/ELF/local-ver-preemptible.s b/test/ELF/local-ver-preemptible.s
new file mode 100644
index 000000000000..b99f700fb2cc
--- /dev/null
+++ b/test/ELF/local-ver-preemptible.s
@@ -0,0 +1,22 @@
+# REQUIRES: x86
+# RUN: echo '.global foo; .type foo, @function; foo:' | \
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t.so.o
+# RUN: ld.lld %t.so.o -o %t.so -shared
+
+# RUN: echo "{ global: main; local: *; };" > %t.script
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o %t.so -o %t -version-script %t.script
+# RUN: llvm-readelf -r --symbols %t | FileCheck %s
+
+# CHECK: Relocation section '.rela.plt' at offset {{.*}} contains 1 entries:
+# CHECK: R_X86_64_JUMP_SLOT 0000000000201020 foo + 0
+
+# CHECK: Symbol table '.dynsym' contains 2 entries:
+# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @
+# CHECK-NEXT: 1: 0000000000201020 0 FUNC GLOBAL DEFAULT UND foo@
+
+.globl _start
+_start:
+ movl $foo - ., %eax
diff --git a/test/ELF/relocatable-rel-iplt.s b/test/ELF/relocatable-rel-iplt.s
new file mode 100644
index 000000000000..773a09f52815
--- /dev/null
+++ b/test/ELF/relocatable-rel-iplt.s
@@ -0,0 +1,56 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i686-- %s -o %t1.o
+# RUN: ld.lld -r %t1.o -o %t2.o
+# RUN: llvm-readobj -t %t2.o | FileCheck %s
+
+// CHECK: Symbols [
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Type: None (0x0)
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Undefined (0x0)
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: (0)
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Type: Section (0x3)
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: .text (0x1)
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: __rel_iplt_end (1)
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Weak (0x2)
+// CHECK-NEXT: Type: None (0x0)
+// CHECK-NEXT: Other [ (0x2)
+// CHECK-NEXT: STV_HIDDEN (0x2)
+// CHECK-NEXT: ]
+// CHECK-NEXT: Section: Undefined (0x0)
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: __rel_iplt_start (16)
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Weak (0x2)
+// CHECK-NEXT: Type: None (0x0)
+// CHECK-NEXT: Other [ (0x2)
+// CHECK-NEXT: STV_HIDDEN (0x2)
+// CHECK-NEXT: ]
+// CHECK-NEXT: Section: Undefined (0x0)
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+
+ movl __rel_iplt_start, %eax
+ movl __rel_iplt_end, %eax
+ ret
+
+ .hidden __rel_iplt_start
+ .hidden __rel_iplt_end
+ .weak __rel_iplt_start
+ .weak __rel_iplt_end