Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Commit a55ceac

Browse files
committedJun 29, 2018
Merge remote-tracking branch 'upstream/release_60' into ldc-release_60
2 parents 977c965 + b051c1d commit a55ceac

13 files changed

+101
-9
lines changed
 

‎COFF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ struct Configuration {
175175
bool AppContainer = false;
176176
bool MinGW = false;
177177
bool WarnLocallyDefinedImported = true;
178+
bool KillAt = false;
178179
};
179180

180181
extern Configuration *Config;

‎COFF/Driver.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,10 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
971971
if (Args.hasArg(OPT_lldsavetemps))
972972
Config->SaveTemps = true;
973973

974+
// Handle /kill-at
975+
if (Args.hasArg(OPT_kill_at))
976+
Config->KillAt = true;
977+
974978
// Handle /lldltocache
975979
if (auto *Arg = Args.getLastArg(OPT_lldltocache))
976980
Config->LTOCache = Arg->getValue();

‎COFF/DriverUtils.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,26 @@ static StringRef undecorate(StringRef Sym) {
561561
return Sym.startswith("_") ? Sym.substr(1) : Sym;
562562
}
563563

564+
// Convert stdcall/fastcall style symbols into unsuffixed symbols,
565+
// with or without a leading underscore. (MinGW specific.)
566+
static StringRef killAt(StringRef Sym, bool Prefix) {
567+
if (Sym.empty())
568+
return Sym;
569+
// Strip any trailing stdcall suffix
570+
Sym = Sym.substr(0, Sym.find('@', 1));
571+
if (!Sym.startswith("@")) {
572+
if (Prefix && !Sym.startswith("_"))
573+
return Saver.save("_" + Sym);
574+
return Sym;
575+
}
576+
// For fastcall, remove the leading @ and replace it with an
577+
// underscore, if prefixes are used.
578+
Sym = Sym.substr(1);
579+
if (Prefix)
580+
Sym = Saver.save("_" + Sym);
581+
return Sym;
582+
}
583+
564584
// Performs error checking on all /export arguments.
565585
// It also sets ordinals.
566586
void fixupExports() {
@@ -593,6 +613,15 @@ void fixupExports() {
593613
}
594614
}
595615

616+
if (Config->KillAt && Config->Machine == I386) {
617+
for (Export &E : Config->Exports) {
618+
E.Name = killAt(E.Name, true);
619+
E.ExportName = killAt(E.ExportName, false);
620+
E.ExtName = killAt(E.ExtName, true);
621+
E.SymbolName = killAt(E.SymbolName, true);
622+
}
623+
}
624+
596625
// Uniquefy by name.
597626
DenseMap<StringRef, Export *> Map(Config->Exports.size());
598627
std::vector<Export> V;

‎COFF/Options.td

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def help_q : Flag<["/?", "-?"], "">, Alias<help>;
121121
def debug_ghash : F<"debug:ghash">;
122122
def debug_dwarf : F<"debug:dwarf">;
123123
def export_all_symbols : F<"export-all-symbols">;
124+
def kill_at : F<"kill-at">;
124125
def lldmingw : F<"lldmingw">;
125126
def msvclto : F<"msvclto">;
126127
def output_def : Joined<["/", "-"], "output-def:">;

‎ELF/Arch/Mips.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
296296
write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2
297297
}
298298

299-
write32<E>(Buf + 24, 0x0320f809); // jalr $25
299+
uint32_t JalrInst = Config->ZHazardplt ? 0x0320fc09 : 0x0320f809;
300+
write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
300301
write32<E>(Buf + 28, 0x2718fffe); // subu $24, $24, 2
301302

302303
uint64_t GotPlt = InX::GotPlt->getVA();
@@ -330,9 +331,12 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
330331
return;
331332
}
332333

334+
uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)
335+
: (Config->ZHazardplt ? 0x03200408 : 0x03200008);
336+
333337
write32<E>(Buf, 0x3c0f0000); // lui $15, %hi(.got.plt entry)
334338
write32<E>(Buf + 4, 0x8df90000); // l[wd] $25, %lo(.got.plt entry)($15)
335-
write32<E>(Buf + 8, isMipsR6() ? 0x03200009 : 0x03200008); // jr $25
339+
write32<E>(Buf + 8, JrInst); // jr $25 / jr.hb $25
336340
write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
337341
writeRelocation<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
338342
writeRelocation<E>(Buf + 4, GotPltEntryAddr, 16, 0);

‎ELF/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct Configuration {
151151
bool WarnMissingEntry;
152152
bool ZCombreloc;
153153
bool ZExecstack;
154+
bool ZHazardplt;
154155
bool ZNocopyreloc;
155156
bool ZNodelete;
156157
bool ZNodlopen;

‎ELF/Driver.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
669669
Config->WarnCommon = Args.hasArg(OPT_warn_common);
670670
Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
671671
Config->ZExecstack = hasZOption(Args, "execstack");
672+
Config->ZHazardplt = hasZOption(Args, "hazardplt");
672673
Config->ZNocopyreloc = hasZOption(Args, "nocopyreloc");
673674
Config->ZNodelete = hasZOption(Args, "nodelete");
674675
Config->ZNodlopen = hasZOption(Args, "nodlopen");

‎MinGW/Driver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) {
154154
Add("-debug:dwarf");
155155
if (Args.hasArg(OPT_large_address_aware))
156156
Add("-largeaddressaware");
157+
if (Args.hasArg(OPT_kill_at))
158+
Add("-kill-at");
157159

158160
if (Args.getLastArgValue(OPT_m) != "thumb2pe" &&
159161
Args.getLastArgValue(OPT_m) != "arm64pe" && !Args.hasArg(OPT_dynamicbase))

‎MinGW/Options.td

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def export_all_symbols: F<"export-all-symbols">,
1414
def gc_sections: F<"gc-sections">, HelpText<"Remove unused sections">;
1515
def icf: J<"icf=">, HelpText<"Identical code folding">;
1616
def image_base: S<"image-base">, HelpText<"Base address of the program">;
17+
def kill_at: F<"kill-at">, HelpText<"Remove @n from exported symbols">;
1718
def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
1819
HelpText<"Root name of library to use">;
1920
def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
@@ -51,6 +52,7 @@ def build_id: F<"build-id">;
5152
def disable_auto_image_base: F<"disable-auto-image-base">;
5253
def enable_auto_image_base: F<"enable-auto-image-base">;
5354
def enable_auto_import: F<"enable-auto-import">;
55+
def end_group: J<"end-group">;
5456
def full_shutdown: Flag<["--"], "full-shutdown">;
5557
def high_entropy_va: F<"high-entropy-va">, HelpText<"Enable 64-bit ASLR">;
5658
def major_image_version: S<"major-image-version">;
@@ -59,6 +61,7 @@ def no_seh: F<"no-seh">;
5961
def nxcompat: F<"nxcompat">, HelpText<"Enable data execution prevention">;
6062
def pic_executable: F<"pic-executable">;
6163
def sysroot: J<"sysroot">, HelpText<"Sysroot">;
64+
def start_group: J<"start-group">;
6265
def tsaware: F<"tsaware">, HelpText<"Create Terminal Server aware executable">;
6366
def v: Flag<["-"], "v">, HelpText<"Display the version number">;
6467
def version: F<"version">, HelpText<"Display the version number and exit">;

‎test/COFF/def-export-stdcall.s

+32-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
# DECORATED-EXPORTS: Name: vectorcall@@8
4747

4848

49-
# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall@8\n @fastcall@8" > %t.def
49+
# GNU tools don't support vectorcall at the moment, but test it for completeness.
50+
# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall@8\n @fastcall@8\n vectorcall@@8" > %t.def
5051
# RUN: lld-link -lldmingw -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
5152
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix DECORATED-MINGW-IMPLIB %s
5253
# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix DECORATED-MINGW-EXPORTS %s
@@ -57,9 +58,39 @@
5758
# DECORATED-MINGW-IMPLIB: Name type: noprefix
5859
# DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall@8
5960
# DECORATED-MINGW-IMPLIB-NEXT: _stdcall@8
61+
# GNU tools don't support vectorcall, but this test is just to track that
62+
# lld's behaviour remains consistent over time.
63+
# DECORATED-MINGW-IMPLIB: Name type: name
64+
# DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
65+
# DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
6066

6167
# DECORATED-MINGW-EXPORTS: Name: @fastcall@8
6268
# DECORATED-MINGW-EXPORTS: Name: stdcall@8
69+
# DECORATED-MINGW-EXPORTS: Name: vectorcall@@8
70+
71+
# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
72+
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB %s
73+
# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix MINGW-KILL-AT-EXPORTS %s
74+
75+
# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll %t.obj -out:%t.dll -implib:%t.lib
76+
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB %s
77+
# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix MINGW-KILL-AT-EXPORTS %s
78+
79+
# MINGW-KILL-AT-IMPLIB: Name type: noprefix
80+
# MINGW-KILL-AT-IMPLIB: __imp__fastcall
81+
# MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
82+
# MINGW-KILL-AT-IMPLIB: Name type: noprefix
83+
# MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
84+
# MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
85+
# GNU tools don't support vectorcall, but this test is just to track that
86+
# lld's behaviour remains consistent over time.
87+
# MINGW-KILL-AT-IMPLIB: Name type: noprefix
88+
# MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
89+
# MINGW-KILL-AT-IMPLIB-NEXT: _vectorcall
90+
91+
# MINGW-KILL-AT-EXPORTS: Name: fastcall
92+
# MINGW-KILL-AT-EXPORTS: Name: stdcall
93+
# MINGW-KILL-AT-EXPORTS: Name: vectorcall
6394

6495

6596
.def _stdcall@8;

‎test/ELF/mips-26-n32-n64.s

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
# RUN: ld.lld %t-so.o -shared -o %t.so
66
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.o
77
# RUN: ld.lld %t.o %t.so -o %t.exe
8-
# RUN: llvm-objdump -d %t.exe | FileCheck %s
8+
# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,DEFAULT
9+
# RUN: ld.lld %t-so.o -shared -o %t.so -z hazardplt
10+
# RUN: ld.lld %t.o %t.so -o %t.exe -z hazardplt
11+
# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,HAZARDPLT
12+
913

1014
# REQUIRES: mips
1115

@@ -21,11 +25,13 @@
2125
# CHECK-NEXT: 2001c: 03 0e c0 23 subu $24, $24, $14
2226
# CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra
2327
# CHECK-NEXT: 20024: 00 18 c0 c2 srl $24, $24, 3
24-
# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25
28+
# DEFAULT: 20028: 03 20 f8 09 jalr $25
29+
# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25
2530
# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2
2631
# CHECK-NEXT: 20030: 3c 0f 00 03 lui $15, 3
2732
# CHECK-NEXT: 20034: 8d f9 00 18 lw $25, 24($15)
28-
# CHECK-NEXT: 20038: 03 20 00 08 jr $25
33+
# DEFAULT: 20038: 03 20 00 08 jr $25
34+
# HAZARDPLT: 20038: 03 20 04 08 jr.hb $25
2935
# CHECK-NEXT: 2003c: 25 f8 00 18 addiu $24, $15, 24
3036

3137
.text

‎test/ELF/mips-plt-r6.s

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
# RUN: -mcpu=mips32r6 %S/Inputs/mips-dynamic.s -o %t2.o
77
# RUN: ld.lld %t2.o -shared -o %t.so
88
# RUN: ld.lld %t1.o %t.so -o %t.exe
9-
# RUN: llvm-objdump -d %t.exe | FileCheck %s
9+
# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=DEFAULT,CHECK
10+
# RUN: ld.lld %t2.o -shared -o %t.so -z hazardplt
11+
# RUN: ld.lld %t1.o %t.so -o %t.exe -z hazardplt
12+
# RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=HAZARDPLT,CHECK
1013

1114
# REQUIRES: mips
1215

@@ -24,12 +27,14 @@
2427
# CHECK-NEXT: 2001c: 03 1c c0 23 subu $24, $24, $gp
2528
# CHECK-NEXT: 20020: 03 e0 78 25 move $15, $ra
2629
# CHECK-NEXT: 20024: 00 18 c0 82 srl $24, $24, 2
27-
# CHECK-NEXT: 20028: 03 20 f8 09 jalr $25
30+
# DEFAULT: 20028: 03 20 f8 09 jalr $25
31+
# HAZARDPLT: 20028: 03 20 fc 09 jalr.hb $25
2832
# CHECK-NEXT: 2002c: 27 18 ff fe addiu $24, $24, -2
2933

3034
# CHECK-NEXT: 20030: 3c 0f 00 03 aui $15, $zero, 3
3135
# CHECK-NEXT: 20034: 8d f9 00 0c lw $25, 12($15)
32-
# CHECK-NEXT: 20038: 03 20 00 09 jr $25
36+
# DEFAULT: 20038: 03 20 00 09 jr $25
37+
# HAZARDPLT: 20038: 03 20 04 09 jr.hb $25
3338
# CHECK-NEXT: 2003c: 25 f8 00 0c addiu $24, $15, 12
3439

3540
.text

‎test/MinGW/driver.test

+4
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ ICF-NONE: -opt:noicf
124124
RUN: ld.lld -### -m i386pep foo.o --icf=all | FileCheck -check-prefix ICF %s
125125
RUN: ld.lld -### -m i386pep foo.o -icf=all | FileCheck -check-prefix ICF %s
126126
ICF: -opt:icf
127+
128+
RUN: ld.lld -### foo.o -m i386pe -shared --kill-at | FileCheck -check-prefix=KILL-AT %s
129+
RUN: ld.lld -### foo.o -m i386pe -shared -kill-at | FileCheck -check-prefix=KILL-AT %s
130+
KILL-AT: -kill-at

0 commit comments

Comments
 (0)
This repository has been archived.