aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-06-27 19:15:02 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-06-27 19:15:02 +0000
commit384e0a667a03156faed5fb21210af8a9288a9122 (patch)
treed6ca6b097f252b802977b508309796c533b94cc5
parentf0d24653c11c321b090f5fce1fef226689eb7930 (diff)
downloadsrc-vendor/lld-60.tar.gz
src-vendor/lld-60.zip
Vendor import of lld 6.0.1 release r335540:vendor/lld/lld-release_601-r335540vendor/lld-60
Notes
Notes: svn path=/vendor/lld/dist-release_60/; revision=335728 svn path=/vendor/lld/lld-release_601-r335540/; revision=335729; tag=vendor/lld/lld-release_601-r335540
-rw-r--r--COFF/Config.h1
-rw-r--r--COFF/Driver.cpp4
-rw-r--r--COFF/DriverUtils.cpp29
-rw-r--r--COFF/Options.td1
-rw-r--r--ELF/Arch/Mips.cpp8
-rw-r--r--ELF/Config.h1
-rw-r--r--ELF/Driver.cpp1
-rw-r--r--MinGW/Driver.cpp2
-rw-r--r--MinGW/Options.td3
-rw-r--r--test/COFF/def-export-stdcall.s33
-rw-r--r--test/ELF/mips-26-n32-n64.s12
-rw-r--r--test/ELF/mips-plt-r6.s11
-rw-r--r--test/MinGW/driver.test4
13 files changed, 101 insertions, 9 deletions
diff --git a/COFF/Config.h b/COFF/Config.h
index 93bef23a97f0..b01689930fac 100644
--- a/COFF/Config.h
+++ b/COFF/Config.h
@@ -175,6 +175,7 @@ struct Configuration {
bool AppContainer = false;
bool MinGW = false;
bool WarnLocallyDefinedImported = true;
+ bool KillAt = false;
};
extern Configuration *Config;
diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp
index 0f3d8fb0b4ef..d4030588e211 100644
--- a/COFF/Driver.cpp
+++ b/COFF/Driver.cpp
@@ -970,6 +970,10 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
if (Args.hasArg(OPT_lldsavetemps))
Config->SaveTemps = true;
+ // Handle /kill-at
+ if (Args.hasArg(OPT_kill_at))
+ Config->KillAt = true;
+
// Handle /lldltocache
if (auto *Arg = Args.getLastArg(OPT_lldltocache))
Config->LTOCache = Arg->getValue();
diff --git a/COFF/DriverUtils.cpp b/COFF/DriverUtils.cpp
index e0641e04a017..4b3b6d5e09d6 100644
--- a/COFF/DriverUtils.cpp
+++ b/COFF/DriverUtils.cpp
@@ -561,6 +561,26 @@ static StringRef undecorate(StringRef Sym) {
return Sym.startswith("_") ? Sym.substr(1) : Sym;
}
+// Convert stdcall/fastcall style symbols into unsuffixed symbols,
+// with or without a leading underscore. (MinGW specific.)
+static StringRef killAt(StringRef Sym, bool Prefix) {
+ if (Sym.empty())
+ return Sym;
+ // Strip any trailing stdcall suffix
+ Sym = Sym.substr(0, Sym.find('@', 1));
+ if (!Sym.startswith("@")) {
+ if (Prefix && !Sym.startswith("_"))
+ return Saver.save("_" + Sym);
+ return Sym;
+ }
+ // For fastcall, remove the leading @ and replace it with an
+ // underscore, if prefixes are used.
+ Sym = Sym.substr(1);
+ if (Prefix)
+ Sym = Saver.save("_" + Sym);
+ return Sym;
+}
+
// Performs error checking on all /export arguments.
// It also sets ordinals.
void fixupExports() {
@@ -593,6 +613,15 @@ void fixupExports() {
}
}
+ if (Config->KillAt && Config->Machine == I386) {
+ for (Export &E : Config->Exports) {
+ E.Name = killAt(E.Name, true);
+ E.ExportName = killAt(E.ExportName, false);
+ E.ExtName = killAt(E.ExtName, true);
+ E.SymbolName = killAt(E.SymbolName, true);
+ }
+ }
+
// Uniquefy by name.
DenseMap<StringRef, Export *> Map(Config->Exports.size());
std::vector<Export> V;
diff --git a/COFF/Options.td b/COFF/Options.td
index 7d4cdba14f75..2a1de14657c1 100644
--- a/COFF/Options.td
+++ b/COFF/Options.td
@@ -121,6 +121,7 @@ def help_q : Flag<["/?", "-?"], "">, Alias<help>;
def debug_ghash : F<"debug:ghash">;
def debug_dwarf : F<"debug:dwarf">;
def export_all_symbols : F<"export-all-symbols">;
+def kill_at : F<"kill-at">;
def lldmingw : F<"lldmingw">;
def msvclto : F<"msvclto">;
def output_def : Joined<["/", "-"], "output-def:">;
diff --git a/ELF/Arch/Mips.cpp b/ELF/Arch/Mips.cpp
index 495e2567006f..e8af36e6d11e 100644
--- a/ELF/Arch/Mips.cpp
+++ b/ELF/Arch/Mips.cpp
@@ -296,7 +296,8 @@ template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2
}
- write32<E>(Buf + 24, 0x0320f809); // jalr $25
+ uint32_t JalrInst = Config->ZHazardplt ? 0x0320fc09 : 0x0320f809;
+ write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
write32<E>(Buf + 28, 0x2718fffe); // subu $24, $24, 2
uint64_t GotPlt = InX::GotPlt->getVA();
@@ -330,9 +331,12 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
return;
}
+ uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)
+ : (Config->ZHazardplt ? 0x03200408 : 0x03200008);
+
write32<E>(Buf, 0x3c0f0000); // lui $15, %hi(.got.plt entry)
write32<E>(Buf + 4, 0x8df90000); // l[wd] $25, %lo(.got.plt entry)($15)
- write32<E>(Buf + 8, isMipsR6() ? 0x03200009 : 0x03200008); // jr $25
+ write32<E>(Buf + 8, JrInst); // jr $25 / jr.hb $25
write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
writeRelocation<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
writeRelocation<E>(Buf + 4, GotPltEntryAddr, 16, 0);
diff --git a/ELF/Config.h b/ELF/Config.h
index ed425720965e..1f244df4d652 100644
--- a/ELF/Config.h
+++ b/ELF/Config.h
@@ -151,6 +151,7 @@ struct Configuration {
bool WarnMissingEntry;
bool ZCombreloc;
bool ZExecstack;
+ bool ZHazardplt;
bool ZNocopyreloc;
bool ZNodelete;
bool ZNodlopen;
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index 714976ae9c4b..44cfa56c94ce 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -668,6 +668,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->WarnCommon = Args.hasArg(OPT_warn_common);
Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
Config->ZExecstack = hasZOption(Args, "execstack");
+ Config->ZHazardplt = hasZOption(Args, "hazardplt");
Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc");
Config->ZNodelete = hasZOption(Args, "nodelete");
Config->ZNodlopen = hasZOption(Args, "nodlopen");
diff --git a/MinGW/Driver.cpp b/MinGW/Driver.cpp
index 6d3bea5d9040..0b7e0831a512 100644
--- a/MinGW/Driver.cpp
+++ b/MinGW/Driver.cpp
@@ -154,6 +154,8 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) {
Add("-debug:dwarf");
if (Args.hasArg(OPT_large_address_aware))
Add("-largeaddressaware");
+ if (Args.hasArg(OPT_kill_at))
+ Add("-kill-at");
if (Args.getLastArgValue(OPT_m) != "thumb2pe" &&
Args.getLastArgValue(OPT_m) != "arm64pe" && !Args.hasArg(OPT_dynamicbase))
diff --git a/MinGW/Options.td b/MinGW/Options.td
index f3bf25a2258b..5baf6cbd93f6 100644
--- a/MinGW/Options.td
+++ b/MinGW/Options.td
@@ -14,6 +14,7 @@ def export_all_symbols: F<"export-all-symbols">,
def gc_sections: F<"gc-sections">, HelpText<"Remove unused sections">;
def icf: J<"icf=">, HelpText<"Identical code folding">;
def image_base: S<"image-base">, HelpText<"Base address of the program">;
+def kill_at: F<"kill-at">, HelpText<"Remove @n from exported symbols">;
def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
HelpText<"Root name of library to use">;
def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
@@ -51,6 +52,7 @@ def build_id: F<"build-id">;
def disable_auto_image_base: F<"disable-auto-image-base">;
def enable_auto_image_base: F<"enable-auto-image-base">;
def enable_auto_import: F<"enable-auto-import">;
+def end_group: J<"end-group">;
def full_shutdown: Flag<["--"], "full-shutdown">;
def high_entropy_va: F<"high-entropy-va">, HelpText<"Enable 64-bit ASLR">;
def major_image_version: S<"major-image-version">;
@@ -59,6 +61,7 @@ def no_seh: F<"no-seh">;
def nxcompat: F<"nxcompat">, HelpText<"Enable data execution prevention">;
def pic_executable: F<"pic-executable">;
def sysroot: J<"sysroot">, HelpText<"Sysroot">;
+def start_group: J<"start-group">;
def tsaware: F<"tsaware">, HelpText<"Create Terminal Server aware executable">;
def v: Flag<["-"], "v">, HelpText<"Display the version number">;
def version: F<"version">, HelpText<"Display the version number and exit">;
diff --git a/test/COFF/def-export-stdcall.s b/test/COFF/def-export-stdcall.s
index 851ac6d975b9..c038ae26f1b4 100644
--- a/test/COFF/def-export-stdcall.s
+++ b/test/COFF/def-export-stdcall.s
@@ -46,7 +46,8 @@
# DECORATED-EXPORTS: Name: vectorcall@@8
-# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall@8\n @fastcall@8" > %t.def
+# GNU tools don't support vectorcall at the moment, but test it for completeness.
+# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall@8\n @fastcall@8\n vectorcall@@8" > %t.def
# RUN: lld-link -lldmingw -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-MINGW-IMPLIB %s
# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix DECORATED-MINGW-EXPORTS %s
@@ -57,9 +58,39 @@
# DECORATED-MINGW-IMPLIB: Name type: noprefix
# DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall@8
# DECORATED-MINGW-IMPLIB-NEXT: _stdcall@8
+# GNU tools don't support vectorcall, but this test is just to track that
+# lld's behaviour remains consistent over time.
+# DECORATED-MINGW-IMPLIB: Name type: name
+# DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
+# DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
# DECORATED-MINGW-EXPORTS: Name: @fastcall@8
# DECORATED-MINGW-EXPORTS: Name: stdcall@8
+# DECORATED-MINGW-EXPORTS: Name: vectorcall@@8
+
+# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
+# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB %s
+# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix MINGW-KILL-AT-EXPORTS %s
+
+# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
+# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB %s
+# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix MINGW-KILL-AT-EXPORTS %s
+
+# MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB: __imp__fastcall
+# MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
+# MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
+# MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
+# GNU tools don't support vectorcall, but this test is just to track that
+# lld's behaviour remains consistent over time.
+# MINGW-KILL-AT-IMPLIB: Name type: noprefix
+# MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
+# MINGW-KILL-AT-IMPLIB-NEXT: _vectorcall
+
+# MINGW-KILL-AT-EXPORTS: Name: fastcall
+# MINGW-KILL-AT-EXPORTS: Name: stdcall
+# MINGW-KILL-AT-EXPORTS: Name: vectorcall
.def _stdcall@8;
diff --git a/test/ELF/mips-26-n32-n64.s b/test/ELF/mips-26-n32-n64.s
index 2e24873332a7..246bf1e9510b 100644
--- a/test/ELF/mips-26-n32-n64.s
+++ b/test/ELF/mips-26-n32-n64.s
@@ -5,7 +5,11 @@
# RUN: ld.lld %t-so.o -shared -o %t.so
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o %t.so -o %t.exe
-# RUN: llvm-objdump -d %t.exe | FileCheck %s
+# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,DEFAULT
+# RUN: ld.lld %t-so.o -shared -o %t.so -z hazardplt
+# RUN: ld.lld %t.o %t.so -o %t.exe -z hazardplt
+# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,HAZARDPLT
+
# REQUIRES: mips
@@ -21,11 +25,13 @@
# CHECK-NEXT: 2001c: 03 0e c0 23 subu $24, $24, $14
# CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra
# CHECK-NEXT: 20024: 00 18 c0 c2 srl $24, $24, 3
-# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25
+# DEFAULT: 20028: 03 20 f8 09 jalr $25
+# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25
# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2
# CHECK-NEXT: 20030: 3c 0f 00 03 lui $15, 3
# CHECK-NEXT: 20034: 8d f9 00 18 lw $25, 24($15)
-# CHECK-NEXT: 20038: 03 20 00 08 jr $25
+# DEFAULT: 20038: 03 20 00 08 jr $25
+# HAZARDPLT: 20038: 03 20 04 08 jr.hb $25
# CHECK-NEXT: 2003c: 25 f8 00 18 addiu $24, $15, 24
.text
diff --git a/test/ELF/mips-plt-r6.s b/test/ELF/mips-plt-r6.s
index 4bab21c32eb9..34e63421a397 100644
--- a/test/ELF/mips-plt-r6.s
+++ b/test/ELF/mips-plt-r6.s
@@ -6,7 +6,10 @@
# RUN: -mcpu=mips32r6 %S/Inputs/mips-dynamic.s -o %t2.o
# RUN: ld.lld %t2.o -shared -o %t.so
# RUN: ld.lld %t1.o %t.so -o %t.exe
-# RUN: llvm-objdump -d %t.exe | FileCheck %s
+# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=DEFAULT,CHECK
+# RUN: ld.lld %t2.o -shared -o %t.so -z hazardplt
+# RUN: ld.lld %t1.o %t.so -o %t.exe -z hazardplt
+# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=HAZARDPLT,CHECK
# REQUIRES: mips
@@ -24,12 +27,14 @@
# CHECK-NEXT: 2001c: 03 1c c0 23 subu $24, $24, $gp
# CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra
# CHECK-NEXT: 20024: 00 18 c0 82 srl $24, $24, 2
-# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25
+# DEFAULT: 20028: 03 20 f8 09 jalr $25
+# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25
# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2
# CHECK-NEXT: 20030: 3c 0f 00 03 aui $15, $zero, 3
# CHECK-NEXT: 20034: 8d f9 00 0c lw $25, 12($15)
-# CHECK-NEXT: 20038: 03 20 00 09 jr $25
+# DEFAULT: 20038: 03 20 00 09 jr $25
+# HAZARDPLT: 20038: 03 20 04 09 jr.hb $25
# CHECK-NEXT: 2003c: 25 f8 00 0c addiu $24, $15, 12
.text
diff --git a/test/MinGW/driver.test b/test/MinGW/driver.test
index 8bf70a9b24fa..45d19be71458 100644
--- a/test/MinGW/driver.test
+++ b/test/MinGW/driver.test
@@ -124,3 +124,7 @@ ICF-NONE: -opt:noicf
RUN: ld.lld -### -m i386pep foo.o --icf=all | FileCheck -check-prefix ICF %s
RUN: ld.lld -### -m i386pep foo.o -icf=all | FileCheck -check-prefix ICF %s
ICF: -opt:icf
+
+RUN: ld.lld -### foo.o -m i386pe -shared --kill-at | FileCheck -check-prefix=KILL-AT %s
+RUN: ld.lld -### foo.o -m i386pe -shared -kill-at | FileCheck -check-prefix=KILL-AT %s
+KILL-AT: -kill-at