authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 15:54:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 15:54:16-04:00
log54e470f9361a0bd9d141f2ff9cd4168fbdd7c16f
tree7742f4c8d20073a6ee346116110eda63468a4b55
parentc9474faa4e6cfd6480c1bd24216c26f4320e3c29
signaturelock-open Commit is signed but in an unrecognized format.

update embedded LLD to 7.0.0rc3


15 files changed, 253 insertions(+), 79 deletions(-)

deps/lld/COFF/Driver.cpp+56-58
......@@ -116,6 +116,19 @@ static std::future<MBErrPair> createFutureForFile(std::string Path) {
116116 });
117117}
118118
119// Symbol names are mangled by prepending "_" on x86.
120static StringRef mangle(StringRef Sym) {
121 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
122 if (Config->Machine == I386)
123 return Saver.save("_" + Sym);
124 return Sym;
125}
126
127static bool findUnderscoreMangle(StringRef Sym) {
128 StringRef Entry = Symtab->findMangle(mangle(Sym));
129 return !Entry.empty() && !isa<Undefined>(Symtab->find(Entry));
130}
131
119132MemoryBufferRef LinkerDriver::takeBuffer(std::unique_ptr<MemoryBuffer> MB) {
120133 MemoryBufferRef MBRef = *MB;
121134 make<std::unique_ptr<MemoryBuffer>>(std::move(MB)); // take ownership
......@@ -407,54 +420,38 @@ Symbol *LinkerDriver::addUndefined(StringRef Name) {
407420 return B;
408421}
409422
410// Symbol names are mangled by appending "_" prefix on x86.
411StringRef LinkerDriver::mangle(StringRef Sym) {
412 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
413 if (Config->Machine == I386)
414 return Saver.save("_" + Sym);
415 return Sym;
416}
417
418423// Windows specific -- find default entry point name.
419424//
420425// There are four different entry point functions for Windows executables,
421426// each of which corresponds to a user-defined "main" function. This function
422427// infers an entry point from a user-defined "main" function.
423428StringRef LinkerDriver::findDefaultEntry() {
429 assert(Config->Subsystem != IMAGE_SUBSYSTEM_UNKNOWN &&
430 "must handle /subsystem before calling this");
431
424432 // As a special case, if /nodefaultlib is given, we directly look for an
425433 // entry point. This is because, if no default library is linked, users
426434 // need to define an entry point instead of a "main".
427 if (Config->NoDefaultLibAll) {
428 for (StringRef S : {"mainCRTStartup", "wmainCRTStartup",
429 "WinMainCRTStartup", "wWinMainCRTStartup"}) {
430 StringRef Entry = Symtab->findMangle(S);
431 if (!Entry.empty() && !isa<Undefined>(Symtab->find(Entry)))
432 return mangle(S);
433 }
434 return "";
435 }
436
437 // User-defined main functions and their corresponding entry points.
438 static const char *Entries[][2] = {
439 {"main", "mainCRTStartup"},
440 {"wmain", "wmainCRTStartup"},
441 {"WinMain", "WinMainCRTStartup"},
442 {"wWinMain", "wWinMainCRTStartup"},
443 };
444 for (auto E : Entries) {
445 StringRef Entry = Symtab->findMangle(mangle(E[0]));
446 if (!Entry.empty() && !isa<Undefined>(Symtab->find(Entry)))
447 return mangle(E[1]);
435 bool FindMain = !Config->NoDefaultLibAll;
436 if (Config->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
437 if (findUnderscoreMangle(FindMain ? "WinMain" : "WinMainCRTStartup"))
438 return mangle("WinMainCRTStartup");
439 if (findUnderscoreMangle(FindMain ? "wWinMain" : "wWinMainCRTStartup"))
440 return mangle("wWinMainCRTStartup");
448441 }
442 if (findUnderscoreMangle(FindMain ? "main" : "mainCRTStartup"))
443 return mangle("mainCRTStartup");
444 if (findUnderscoreMangle(FindMain ? "wmain" : "wmainCRTStartup"))
445 return mangle("wmainCRTStartup");
449446 return "";
450447}
451448
452449WindowsSubsystem LinkerDriver::inferSubsystem() {
453450 if (Config->DLL)
454451 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
455 if (Symtab->findUnderscore("main") || Symtab->findUnderscore("wmain"))
452 if (findUnderscoreMangle("main") || findUnderscoreMangle("wmain"))
456453 return IMAGE_SUBSYSTEM_WINDOWS_CUI;
457 if (Symtab->findUnderscore("WinMain") || Symtab->findUnderscore("wWinMain"))
454 if (findUnderscoreMangle("WinMain") || findUnderscoreMangle("wWinMain"))
458455 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
459456 return IMAGE_SUBSYSTEM_UNKNOWN;
460457}
......@@ -1335,25 +1332,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
13351332 error("/dynamicbase:no is not compatible with " +
13361333 machineToStr(Config->Machine));
13371334
1338 // Handle /entry and /dll
1339 if (auto *Arg = Args.getLastArg(OPT_entry)) {
1340 Config->Entry = addUndefined(mangle(Arg->getValue()));
1341 } else if (!Config->Entry && !Config->NoEntry) {
1342 if (Args.hasArg(OPT_dll)) {
1343 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
1344 : "_DllMainCRTStartup";
1345 Config->Entry = addUndefined(S);
1346 } else {
1347 // Windows specific -- If entry point name is not given, we need to
1348 // infer that from user-defined entry name.
1349 StringRef S = findDefaultEntry();
1350 if (S.empty())
1351 fatal("entry point must be defined");
1352 Config->Entry = addUndefined(S);
1353 log("Entry name inferred: " + S);
1354 }
1355 }
1356
13571335 // Handle /export
13581336 for (auto *Arg : Args.filtered(OPT_export)) {
13591337 Export E = parseExport(Arg->getValue());
......@@ -1379,6 +1357,34 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
13791357 return;
13801358 }
13811359
1360 // Windows specific -- if no /subsystem is given, we need to infer
1361 // that from entry point name. Must happen before /entry handling,
1362 // and after the early return when just writing an import library.
1363 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
1364 Config->Subsystem = inferSubsystem();
1365 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
1366 fatal("subsystem must be defined");
1367 }
1368
1369 // Handle /entry and /dll
1370 if (auto *Arg = Args.getLastArg(OPT_entry)) {
1371 Config->Entry = addUndefined(mangle(Arg->getValue()));
1372 } else if (!Config->Entry && !Config->NoEntry) {
1373 if (Args.hasArg(OPT_dll)) {
1374 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
1375 : "_DllMainCRTStartup";
1376 Config->Entry = addUndefined(S);
1377 } else {
1378 // Windows specific -- If entry point name is not given, we need to
1379 // infer that from user-defined entry name.
1380 StringRef S = findDefaultEntry();
1381 if (S.empty())
1382 fatal("entry point must be defined");
1383 Config->Entry = addUndefined(S);
1384 log("Entry name inferred: " + S);
1385 }
1386 }
1387
13821388 // Handle /delayload
13831389 for (auto *Arg : Args.filtered(OPT_delayload)) {
13841390 Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
......@@ -1491,14 +1497,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
14911497 if (errorCount())
14921498 return;
14931499
1494 // Windows specific -- if no /subsystem is given, we need to infer
1495 // that from entry point name.
1496 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
1497 Config->Subsystem = inferSubsystem();
1498 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
1499 fatal("subsystem must be defined");
1500 }
1501
15021500 // Handle /safeseh.
15031501 if (Args.hasFlag(OPT_safeseh, OPT_safeseh_no, false)) {
15041502 for (ObjFile *File : ObjFile::Instances)
deps/lld/COFF/Driver.h-1
......@@ -103,7 +103,6 @@ private:
103103 std::set<std::string> VisitedLibs;
104104
105105 Symbol *addUndefined(StringRef Sym);
106 StringRef mangle(StringRef Sym);
107106
108107 // Windows specific -- "main" is not the only main function in Windows.
109108 // You can choose one from these four -- {w,}{WinMain,main}.
deps/lld/docs/ReleaseNotes.rst+10-12
......@@ -5,18 +5,13 @@ LLD 7.0.0 Release Notes
55.. contents::
66 :local:
77
8.. warning::
9 These are in-progress notes for the upcoming LLVM 7.0.0 release.
10 Release notes for previous releases can be found on
11 `the Download Page <http://releases.llvm.org/download.html>`_.
12
138Introduction
149============
1510
1611This document contains the release notes for the lld linker, release 7.0.0.
1712Here we describe the status of lld, including major improvements
1813from the previous release. All lld releases may be downloaded
19from the `LLVM releases web site <http://llvm.org/releases/>`_.
14from the `LLVM releases web site <https://llvm.org/releases/>`_.
2015
2116Non-comprehensive list of changes in this release
2217=================================================
......@@ -24,7 +19,15 @@ Non-comprehensive list of changes in this release
2419ELF Improvements
2520----------------
2621
27* Item 1.
22* lld is now able to overcome MIPS GOT entries number limitation
23 and generate multi-GOT if necessary.
24
25* lld is now able to produce MIPS position-independent executable (PIE).
26
27* Fixed MIPS TLS GOT entries for local symbols in shared libraries.
28
29* Fixed calculation of MIPS GP relative relocations
30 in case of relocatable output.
2831
2932COFF Improvements
3033-----------------
......@@ -36,8 +39,3 @@ COFF Improvements
3639* Added support for outputting PDB debug info for MinGW targets.
3740
3841* Improved compatibility of output binaries with GNU binutils objcopy/strip.
39
40MachO Improvements
41------------------
42
43* Item 1.
deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp+1
......@@ -621,6 +621,7 @@ void ArchHandler_x86_64::applyFixupFinal(
621621 // Fall into llvm_unreachable().
622622 break;
623623 }
624 llvm_unreachable("invalid x86_64 Reference Kind");
624625}
625626
626627void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,
deps/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h+4-5
......@@ -186,11 +186,10 @@ packRelocation(const Relocation &r, bool swap, bool isBigEndian) {
186186}
187187
188188inline StringRef getString16(const char s[16]) {
189 StringRef x = s;
190 if ( x.size() > 16 )
191 return x.substr(0, 16);
192 else
193 return x;
189 // The StringRef(const char *) constructor passes the const char * to
190 // strlen(), so we can't use this constructor here, because if there is no
191 // null terminator in s, then strlen() will read past the end of the array.
192 return StringRef(s, strnlen(s, 16));
194193}
195194
196195inline void setString16(StringRef str, char s[16]) {
deps/lld/test/COFF/entry-inference3.test+7-3
......@@ -1,5 +1,9 @@
1# RUN: yaml2obj < %s > %t.obj
2# RUN: not lld-link /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
1# RUN: sed -e s/ENTRYNAME/mainCRTStartup/ %s | yaml2obj > %t.obj
2# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
3# RUN: FileCheck %s < %t.log
4
5# RUN: sed -e s/ENTRYNAME/?mainCRTStartup@@YAHXZ/ %s | yaml2obj > %t.obj
6# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
37# RUN: FileCheck %s < %t.log
48
59# CHECK: Entry name inferred: mainCRTStartup
......@@ -26,7 +30,7 @@ symbols:
2630 NumberOfLinenumbers: 0
2731 CheckSum: 0
2832 Number: 0
29 - Name: mainCRTStartup
33 - Name: "ENTRYNAME"
3034 Value: 0
3135 SectionNumber: 1
3236 SimpleType: IMAGE_SYM_TYPE_NULL
deps/lld/test/COFF/entry-inference332.test created+39
......@@ -0,0 +1,39 @@
1# RUN: sed -e s/ENTRYNAME/_mainCRTStartup/ %s | yaml2obj > %t.obj
2# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
3# RUN: FileCheck %s < %t.log
4
5# RUN: sed -e s/ENTRYNAME/?mainCRTStartup@@YAHXZ/ %s | yaml2obj > %t.obj
6# RUN: lld-link /subsystem:console /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
7# RUN: FileCheck %s < %t.log
8
9# CHECK: Entry name inferred: _mainCRTStartup
10
11--- !COFF
12header:
13 Machine: IMAGE_FILE_MACHINE_I386
14 Characteristics: []
15sections:
16 - Name: .text
17 Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
18 Alignment: 4
19 SectionData: B82A000000C3
20symbols:
21 - Name: .text
22 Value: 0
23 SectionNumber: 1
24 SimpleType: IMAGE_SYM_TYPE_NULL
25 ComplexType: IMAGE_SYM_DTYPE_NULL
26 StorageClass: IMAGE_SYM_CLASS_STATIC
27 SectionDefinition:
28 Length: 6
29 NumberOfRelocations: 0
30 NumberOfLinenumbers: 0
31 CheckSum: 0
32 Number: 0
33 - Name: "ENTRYNAME"
34 Value: 0
35 SectionNumber: 1
36 SimpleType: IMAGE_SYM_TYPE_NULL
37 ComplexType: IMAGE_SYM_DTYPE_NULL
38 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
39...
deps/lld/test/COFF/entry-inference4.test created+56
......@@ -0,0 +1,56 @@
1# RUN: sed 's/ENTRY1/WinMain/;s/ENTRY2/main/' %s | yaml2obj > %t.obj
2# RUN: not lld-link /subsystem:windows /out:%t.exe %t.obj > %t.log 2>&1
3# RUN: FileCheck -check-prefix=WINMAIN %s < %t.log
4
5# RUN: sed 's/ENTRY1/wWinMain/;s/ENTRY2/main/' %s | yaml2obj > %t.obj
6# RUN: not lld-link /subsystem:windows /out:%t.exe %t.obj > %t.log 2>&1
7# RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log
8
9# RUN: sed 's/ENTRY1/WinMain/;s/ENTRY2/main/' %s | yaml2obj > %t.obj
10# RUN: not lld-link /subsystem:console /out:%t.exe %t.obj > %t.log 2>&1
11# RUN: FileCheck -check-prefix=MAIN %s < %t.log
12
13# RUN: sed 's/ENTRY1/WinMain/;s/ENTRY2/wmain/' %s | yaml2obj > %t.obj
14# RUN: not lld-link /subsystem:console /out:%t.exe %t.obj > %t.log 2>&1
15# RUN: FileCheck -check-prefix=WMAIN %s < %t.log
16
17# MAIN: error: <root>: undefined symbol: mainCRTStartup
18# WMAIN: error: <root>: undefined symbol: wmainCRTStartup
19# WINMAIN: error: <root>: undefined symbol: WinMainCRTStartup
20# WWINMAIN: error: <root>: undefined symbol: wWinMainCRTStartup
21
22--- !COFF
23header:
24 Machine: IMAGE_FILE_MACHINE_AMD64
25 Characteristics: []
26sections:
27 - Name: .text
28 Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
29 Alignment: 4
30 SectionData: B82A000000C3
31symbols:
32 - Name: .text
33 Value: 0
34 SectionNumber: 1
35 SimpleType: IMAGE_SYM_TYPE_NULL
36 ComplexType: IMAGE_SYM_DTYPE_NULL
37 StorageClass: IMAGE_SYM_CLASS_STATIC
38 SectionDefinition:
39 Length: 6
40 NumberOfRelocations: 0
41 NumberOfLinenumbers: 0
42 CheckSum: 0
43 Number: 0
44 - Name: ENTRY1
45 Value: 0
46 SectionNumber: 1
47 SimpleType: IMAGE_SYM_TYPE_NULL
48 ComplexType: IMAGE_SYM_DTYPE_NULL
49 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
50 - Name: ENTRY2
51 Value: 0
52 SectionNumber: 1
53 SimpleType: IMAGE_SYM_TYPE_NULL
54 ComplexType: IMAGE_SYM_DTYPE_NULL
55 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
56...
deps/lld/test/COFF/guardcf-align.s+1
......@@ -1,3 +1,4 @@
1# REQUIRES: x86
12# RUN: llvm-mc -triple x86_64-windows-msvc -filetype=obj -o %t.obj %s
23# RUN: yaml2obj < %p/Inputs/guardcf-align-foobar.yaml \
34# RUN: > %T/guardcf-align-foobar.obj
deps/lld/test/COFF/subsystem-inference32.test created+74
......@@ -0,0 +1,74 @@
1# RUN: sed -e s/ENTRYNAME/_main/ %s | yaml2obj > %t.obj
2# RUN: lld-link /out:%t.exe %t.obj
3# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=MAIN %s
4
5# RUN: sed s/ENTRYNAME/_wmain/ %s | yaml2obj > %t.obj
6# RUN: lld-link /out:%t.exe %t.obj
7# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WMAIN %s
8
9# RUN: sed s/ENTRYNAME/_WinMain@16/ %s | yaml2obj > %t.obj
10# RUN: lld-link /out:%t.exe %t.obj
11# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WINMAIN %s
12
13# RUN: sed s/ENTRYNAME/_wWinMain@16/ %s | yaml2obj > %t.obj
14# RUN: lld-link /out:%t.exe %t.obj
15# RUN: llvm-readobj -file-headers %t.exe | FileCheck -check-prefix=WWINMAIN %s
16
17# MAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
18# WMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI
19# WINMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
20# WWINMAIN: Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI
21
22--- !COFF
23header:
24 Machine: IMAGE_FILE_MACHINE_I386
25 Characteristics: []
26sections:
27 - Name: .text
28 Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
29 Alignment: 4
30 SectionData: B82A000000C3
31symbols:
32 - Name: .text
33 Value: 0
34 SectionNumber: 1
35 SimpleType: IMAGE_SYM_TYPE_NULL
36 ComplexType: IMAGE_SYM_DTYPE_NULL
37 StorageClass: IMAGE_SYM_CLASS_STATIC
38 SectionDefinition:
39 Length: 6
40 NumberOfRelocations: 0
41 NumberOfLinenumbers: 0
42 CheckSum: 0
43 Number: 0
44 - Name: ENTRYNAME
45 Value: 0
46 SectionNumber: 1
47 SimpleType: IMAGE_SYM_TYPE_NULL
48 ComplexType: IMAGE_SYM_DTYPE_NULL
49 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
50 - Name: _mainCRTStartup
51 Value: 0
52 SectionNumber: 1
53 SimpleType: IMAGE_SYM_TYPE_NULL
54 ComplexType: IMAGE_SYM_DTYPE_NULL
55 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
56 - Name: _wmainCRTStartup
57 Value: 0
58 SectionNumber: 1
59 SimpleType: IMAGE_SYM_TYPE_NULL
60 ComplexType: IMAGE_SYM_DTYPE_NULL
61 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
62 - Name: _WinMainCRTStartup
63 Value: 0
64 SectionNumber: 1
65 SimpleType: IMAGE_SYM_TYPE_NULL
66 ComplexType: IMAGE_SYM_DTYPE_NULL
67 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
68 - Name: _wWinMainCRTStartup
69 Value: 0
70 SectionNumber: 1
71 SimpleType: IMAGE_SYM_TYPE_NULL
72 ComplexType: IMAGE_SYM_DTYPE_NULL
73 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
74...
deps/lld/test/ELF/icf13.s+1
......@@ -1,3 +1,4 @@
1# REQUIRES: x86
12# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
23# RUN: ld.lld -shared -z notext %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s
34
deps/lld/test/ELF/icf15.s+1
......@@ -1,3 +1,4 @@
1# REQUIRES: x86
12# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
23# RUN: ld.lld %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s
34
deps/lld/test/ELF/icf16.s+1
......@@ -1,3 +1,4 @@
1# REQUIRES: x86
12# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
23# RUN: ld.lld -shared -z notext %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s
34
deps/lld/test/ELF/icf17.s+1
......@@ -1,3 +1,4 @@
1# REQUIRES: x86
12# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
23# RUN: ld.lld %t1 -o /dev/null --icf=all --print-icf-sections 2>&1 | FileCheck -allow-empty %s
34
deps/lld/test/ELF/lto/libcall-archive.ll+1
......@@ -1,3 +1,4 @@
1; REQUIRES: x86
12; RUN: rm -f %t.a
23; RUN: llvm-as -o %t.o %s
34; RUN: llvm-as -o %t2.o %S/Inputs/libcall-archive.ll