authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:10:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:10:12-04:00
log016a59e3a155894412ccf3d98fe6ac1054243d06
treebb71096f2dad14d3389dca10d48302cc55700792
parent185cb1327806f073b91218ff2fd6f21d95060c00
signature Commit is signed but in an unrecognized format.

update embedded LLD to 9.0.0rc4


33 files changed, 555 insertions(+), 190 deletions(-)

deps/lld/CMakeLists.txt-1
......@@ -56,7 +56,6 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
5656 include(HandleLLVMOptions)
5757
5858 if(LLVM_INCLUDE_TESTS)
59 set(Python_ADDITIONAL_VERSIONS 2.7)
6059 include(FindPythonInterp)
6160 if(NOT PYTHONINTERP_FOUND)
6261 message(FATAL_ERROR
deps/lld/COFF/Config.h+1
......@@ -189,6 +189,7 @@ struct Configuration {
189189 // Used for /thinlto-object-suffix-replace:
190190 std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
191191
192 uint64_t align = 4096;
192193 uint64_t imageBase = -1;
193194 uint64_t fileAlign = 512;
194195 uint64_t stackReserve = 1024 * 1024;
deps/lld/COFF/Driver.cpp+32-8
......@@ -36,6 +36,7 @@
3636#include "llvm/Option/Option.h"
3737#include "llvm/Support/Debug.h"
3838#include "llvm/Support/LEB128.h"
39#include "llvm/Support/MathExtras.h"
3940#include "llvm/Support/Path.h"
4041#include "llvm/Support/Process.h"
4142#include "llvm/Support/TarWriter.h"
......@@ -270,13 +271,12 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
270271}
271272
272273void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
273 StringRef symName,
274 const Archive::Symbol &sym,
274275 StringRef parentName) {
275276
276 auto reportBufferError = [=](Error &&e,
277 StringRef childName) {
277 auto reportBufferError = [=](Error &&e, StringRef childName) {
278278 fatal("could not get the buffer for the member defining symbol " +
279 symName + ": " + parentName + "(" + childName + "): " +
279 toCOFFString(sym) + ": " + parentName + "(" + childName + "): " +
280280 toString(std::move(e)));
281281 };
282282
......@@ -287,7 +287,8 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
287287 reportBufferError(mbOrErr.takeError(), check(c.getFullName()));
288288 MemoryBufferRef mb = mbOrErr.get();
289289 enqueueTask([=]() {
290 driver->addArchiveBuffer(mb, symName, parentName, offsetInArchive);
290 driver->addArchiveBuffer(mb, toCOFFString(sym), parentName,
291 offsetInArchive);
291292 });
292293 return;
293294 }
......@@ -295,15 +296,16 @@ void LinkerDriver::enqueueArchiveMember(const Archive::Child &c,
295296 std::string childName = CHECK(
296297 c.getFullName(),
297298 "could not get the filename for the member defining symbol " +
298 symName);
299 toCOFFString(sym));
299300 auto future = std::make_shared<std::future<MBErrPair>>(
300301 createFutureForFile(childName));
301302 enqueueTask([=]() {
302303 auto mbOrErr = future->get();
303304 if (mbOrErr.second)
304305 reportBufferError(errorCodeToError(mbOrErr.second), childName);
305 driver->addArchiveBuffer(takeBuffer(std::move(mbOrErr.first)), symName,
306 parentName, /* OffsetInArchive */ 0);
306 driver->addArchiveBuffer(takeBuffer(std::move(mbOrErr.first)),
307 toCOFFString(sym), parentName,
308 /*OffsetInArchive=*/0);
307309 });
308310}
309311
......@@ -1053,6 +1055,12 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
10531055 });
10541056}
10551057
1058static const char *libcallRoutineNames[] = {
1059#define HANDLE_LIBCALL(code, name) name,
1060#include "llvm/IR/RuntimeLibcalls.def"
1061#undef HANDLE_LIBCALL
1062};
1063
10561064void LinkerDriver::link(ArrayRef<const char *> argsArr) {
10571065 // Needed for LTO.
10581066 InitializeAllTargetInfos();
......@@ -1421,6 +1429,13 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
14211429 for (auto *arg : args.filtered(OPT_section))
14221430 parseSection(arg->getValue());
14231431
1432 // Handle /align
1433 if (auto *arg = args.getLastArg(OPT_align)) {
1434 parseNumbers(arg->getValue(), &config->align);
1435 if (!isPowerOf2_64(config->align))
1436 error("/align: not a power of two: " + StringRef(arg->getValue()));
1437 }
1438
14241439 // Handle /aligncomm
14251440 for (auto *arg : args.filtered(OPT_aligncomm))
14261441 parseAligncomm(arg->getValue());
......@@ -1748,6 +1763,15 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
17481763 u->weakAlias = symtab->addUndefined(to);
17491764 }
17501765
1766 // If any inputs are bitcode files, the LTO code generator may create
1767 // references to library functions that are not explicit in the bitcode
1768 // file's symbol table. If any of those library functions are defined in a
1769 // bitcode file in an archive member, we need to arrange to use LTO to
1770 // compile those archive members by adding them to the link beforehand.
1771 if (!BitcodeFile::instances.empty())
1772 for (const char *s : libcallRoutineNames)
1773 symtab->addLibcall(s);
1774
17511775 // Windows specific -- if __load_config_used can be resolved, resolve it.
17521776 if (symtab->findUnderscore("_load_config_used"))
17531777 addUndefined(mangle("_load_config_used"));
deps/lld/COFF/Driver.h+1-1
......@@ -72,7 +72,7 @@ public:
7272 void parseDirectives(InputFile *file);
7373
7474 // Used by ArchiveFile to enqueue members.
75 void enqueueArchiveMember(const Archive::Child &c, StringRef symName,
75 void enqueueArchiveMember(const Archive::Child &c, const Archive::Symbol &sym,
7676 StringRef parentName);
7777
7878 MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> mb);
deps/lld/COFF/InputFiles.cpp+4-4
......@@ -85,16 +85,16 @@ void ArchiveFile::parse() {
8585}
8686
8787// Returns a buffer pointing to a member file containing a given symbol.
88void ArchiveFile::addMember(const Archive::Symbol *sym) {
88void ArchiveFile::addMember(const Archive::Symbol &sym) {
8989 const Archive::Child &c =
90 CHECK(sym->getMember(),
91 "could not get the member for symbol " + sym->getName());
90 CHECK(sym.getMember(),
91 "could not get the member for symbol " + toCOFFString(sym));
9292
9393 // Return an empty buffer if we have already returned the same buffer.
9494 if (!seen.insert(c.getChildOffset()).second)
9595 return;
9696
97 driver->enqueueArchiveMember(c, sym->getName(), getName());
97 driver->enqueueArchiveMember(c, sym, getName());
9898}
9999
100100std::vector<MemoryBufferRef> getArchiveMembers(Archive *file) {
deps/lld/COFF/InputFiles.h+1-1
......@@ -96,7 +96,7 @@ public:
9696 // Enqueues an archive member load for the given symbol. If we've already
9797 // enqueued a load for the same archive member, this function does nothing,
9898 // which ensures that we don't load the same member more than once.
99 void addMember(const Archive::Symbol *sym);
99 void addMember(const Archive::Symbol &sym);
100100
101101private:
102102 std::unique_ptr<Archive> file;
deps/lld/COFF/SymbolTable.cpp+16-4
......@@ -179,7 +179,7 @@ void SymbolTable::loadMinGWAutomaticImports() {
179179 log("Loading lazy " + l->getName() + " from " + l->file->getName() +
180180 " for automatic import");
181181 l->pendingArchiveLoad = true;
182 l->file->addMember(&l->sym);
182 l->file->addMember(l->sym);
183183 }
184184}
185185
......@@ -363,13 +363,13 @@ Symbol *SymbolTable::addUndefined(StringRef name, InputFile *f,
363363 if (auto *l = dyn_cast<Lazy>(s)) {
364364 if (!s->pendingArchiveLoad) {
365365 s->pendingArchiveLoad = true;
366 l->file->addMember(&l->sym);
366 l->file->addMember(l->sym);
367367 }
368368 }
369369 return s;
370370}
371371
372void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol sym) {
372void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol &sym) {
373373 StringRef name = sym.getName();
374374 Symbol *s;
375375 bool wasInserted;
......@@ -382,7 +382,7 @@ void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol sym) {
382382 if (!u || u->weakAlias || s->pendingArchiveLoad)
383383 return;
384384 s->pendingArchiveLoad = true;
385 f->addMember(&sym);
385 f->addMember(sym);
386386}
387387
388388void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile) {
......@@ -505,6 +505,18 @@ Symbol *SymbolTable::addImportThunk(StringRef name, DefinedImportData *id,
505505 return nullptr;
506506}
507507
508void SymbolTable::addLibcall(StringRef name) {
509 Symbol *sym = findUnderscore(name);
510 if (!sym)
511 return;
512
513 if (Lazy *l = dyn_cast<Lazy>(sym)) {
514 MemoryBufferRef mb = l->getMemberBuffer();
515 if (identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode)
516 addUndefined(sym->getName());
517 }
518}
519
508520std::vector<Chunk *> SymbolTable::getChunks() {
509521 std::vector<Chunk *> res;
510522 for (ObjFile *file : ObjFile::instances) {
deps/lld/COFF/SymbolTable.h+2-1
......@@ -83,7 +83,7 @@ public:
8383 Symbol *addAbsolute(StringRef n, uint64_t va);
8484
8585 Symbol *addUndefined(StringRef name, InputFile *f, bool isWeakAlias);
86 void addLazy(ArchiveFile *f, const Archive::Symbol sym);
86 void addLazy(ArchiveFile *f, const Archive::Symbol &sym);
8787 Symbol *addAbsolute(StringRef n, COFFSymbolRef s);
8888 Symbol *addRegular(InputFile *f, StringRef n,
8989 const llvm::object::coff_symbol_generic *s = nullptr,
......@@ -97,6 +97,7 @@ public:
9797 Symbol *addImportData(StringRef n, ImportFile *f);
9898 Symbol *addImportThunk(StringRef name, DefinedImportData *s,
9999 uint16_t machine);
100 void addLibcall(StringRef name);
100101
101102 void reportDuplicate(Symbol *existing, InputFile *newFile);
102103
deps/lld/COFF/Symbols.cpp+18-4
......@@ -20,18 +20,23 @@ using namespace llvm::object;
2020
2121using namespace lld::coff;
2222
23namespace lld {
24
2325static_assert(sizeof(SymbolUnion) <= 48,
2426 "symbols should be optimized for memory usage");
2527
2628// Returns a symbol name for an error message.
27std::string lld::toString(coff::Symbol &b) {
29static std::string demangle(StringRef symName) {
2830 if (config->demangle)
29 if (Optional<std::string> s = lld::demangleMSVC(b.getName()))
31 if (Optional<std::string> s = demangleMSVC(symName))
3032 return *s;
31 return b.getName();
33 return symName;
34}
35std::string toString(coff::Symbol &b) { return demangle(b.getName()); }
36std::string toCOFFString(const Archive::Symbol &b) {
37 return demangle(b.getName());
3238}
3339
34namespace lld {
3540namespace coff {
3641
3742StringRef Symbol::getName() {
......@@ -113,5 +118,14 @@ Defined *Undefined::getWeakAlias() {
113118 return d;
114119 return nullptr;
115120}
121
122MemoryBufferRef Lazy::getMemberBuffer() {
123 Archive::Child c =
124 CHECK(sym.getMember(),
125 "could not get the member for symbol " + toCOFFString(sym));
126 return CHECK(c.getMemoryBufferRef(),
127 "could not get the buffer for the member defining symbol " +
128 toCOFFString(sym));
129}
116130} // namespace coff
117131} // namespace lld
deps/lld/COFF/Symbols.h+10-1
......@@ -21,6 +21,14 @@
2121#include <vector>
2222
2323namespace lld {
24
25std::string toString(coff::Symbol &b);
26
27// There are two different ways to convert an Archive::Symbol to a string:
28// One for Microsoft name mangling and one for Itanium name mangling.
29// Call the functions toCOFFString and toELFString, not just toString.
30std::string toCOFFString(const coff::Archive::Symbol &b);
31
2432namespace coff {
2533
2634using llvm::object::Archive;
......@@ -257,6 +265,8 @@ public:
257265
258266 static bool classof(const Symbol *s) { return s->kind() == LazyKind; }
259267
268 MemoryBufferRef getMemberBuffer();
269
260270 ArchiveFile *file;
261271
262272private:
......@@ -429,7 +439,6 @@ void replaceSymbol(Symbol *s, ArgT &&... arg) {
429439}
430440} // namespace coff
431441
432std::string toString(coff::Symbol &b);
433442} // namespace lld
434443
435444#endif
deps/lld/COFF/Writer.cpp+9-4
......@@ -626,6 +626,9 @@ void Writer::run() {
626626
627627 writeMapFile(outputSections);
628628
629 if (errorCount())
630 return;
631
629632 ScopedTimer t2(diskCommitTimer);
630633 if (auto e = buffer->commit())
631634 fatal("failed to write the output file: " + toString(std::move(e)));
......@@ -1205,9 +1208,11 @@ void Writer::assignAddresses() {
12051208 sizeOfHeaders +=
12061209 config->is64() ? sizeof(pe32plus_header) : sizeof(pe32_header);
12071210 sizeOfHeaders = alignTo(sizeOfHeaders, config->fileAlign);
1208 uint64_t rva = pageSize; // The first page is kept unmapped.
12091211 fileSize = sizeOfHeaders;
12101212
1213 // The first page is kept unmapped.
1214 uint64_t rva = alignTo(sizeOfHeaders, config->align);
1215
12111216 for (OutputSection *sec : outputSections) {
12121217 if (sec == relocSec)
12131218 addBaserels();
......@@ -1237,10 +1242,10 @@ void Writer::assignAddresses() {
12371242 sec->header.SizeOfRawData = rawSize;
12381243 if (rawSize != 0)
12391244 sec->header.PointerToRawData = fileSize;
1240 rva += alignTo(virtualSize, pageSize);
1245 rva += alignTo(virtualSize, config->align);
12411246 fileSize += alignTo(rawSize, config->fileAlign);
12421247 }
1243 sizeOfImage = alignTo(rva, pageSize);
1248 sizeOfImage = alignTo(rva, config->align);
12441249
12451250 // Assign addresses to sections in MergeChunks.
12461251 for (MergeChunk *mc : MergeChunk::instances)
......@@ -1309,7 +1314,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
13091314 pe->MinorLinkerVersion = 0;
13101315
13111316 pe->ImageBase = config->imageBase;
1312 pe->SectionAlignment = pageSize;
1317 pe->SectionAlignment = config->align;
13131318 pe->FileAlignment = config->fileAlign;
13141319 pe->MajorImageVersion = config->majorImageVersion;
13151320 pe->MinorImageVersion = config->minorImageVersion;
deps/lld/ELF/Arch/PPC.cpp+11-2
......@@ -190,6 +190,13 @@ bool PPC::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
190190RelExpr PPC::getRelExpr(RelType type, const Symbol &s,
191191 const uint8_t *loc) const {
192192 switch (type) {
193 case R_PPC_NONE:
194 return R_NONE;
195 case R_PPC_ADDR16_HA:
196 case R_PPC_ADDR16_HI:
197 case R_PPC_ADDR16_LO:
198 case R_PPC_ADDR32:
199 return R_ABS;
193200 case R_PPC_DTPREL16:
194201 case R_PPC_DTPREL16_HA:
195202 case R_PPC_DTPREL16_HI:
......@@ -227,7 +234,9 @@ RelExpr PPC::getRelExpr(RelType type, const Symbol &s,
227234 case R_PPC_TPREL16_HI:
228235 return R_TLS;
229236 default:
230 return R_ABS;
237 error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
238 ") against symbol " + toString(s));
239 return R_NONE;
231240 }
232241}
233242
......@@ -319,7 +328,7 @@ void PPC::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
319328 break;
320329 }
321330 default:
322 error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
331 llvm_unreachable("unknown relocation");
323332 }
324333}
325334
deps/lld/ELF/Arch/PPC64.cpp+20-2
......@@ -532,6 +532,21 @@ void PPC64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {
532532RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,
533533 const uint8_t *loc) const {
534534 switch (type) {
535 case R_PPC64_NONE:
536 return R_NONE;
537 case R_PPC64_ADDR16:
538 case R_PPC64_ADDR16_DS:
539 case R_PPC64_ADDR16_HA:
540 case R_PPC64_ADDR16_HI:
541 case R_PPC64_ADDR16_HIGHER:
542 case R_PPC64_ADDR16_HIGHERA:
543 case R_PPC64_ADDR16_HIGHEST:
544 case R_PPC64_ADDR16_HIGHESTA:
545 case R_PPC64_ADDR16_LO:
546 case R_PPC64_ADDR16_LO_DS:
547 case R_PPC64_ADDR32:
548 case R_PPC64_ADDR64:
549 return R_ABS;
535550 case R_PPC64_GOT16:
536551 case R_PPC64_GOT16_DS:
537552 case R_PPC64_GOT16_HA:
......@@ -554,6 +569,7 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,
554569 return R_PPC64_CALL_PLT;
555570 case R_PPC64_REL16_LO:
556571 case R_PPC64_REL16_HA:
572 case R_PPC64_REL16_HI:
557573 case R_PPC64_REL32:
558574 case R_PPC64_REL64:
559575 return R_PC;
......@@ -607,7 +623,9 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,
607623 case R_PPC64_TLS:
608624 return R_TLSIE_HINT;
609625 default:
610 return R_ABS;
626 error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
627 ") against symbol " + toString(s));
628 return R_NONE;
611629 }
612630}
613631
......@@ -870,7 +888,7 @@ void PPC64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
870888 write64(loc, val - dynamicThreadPointerOffset);
871889 break;
872890 default:
873 error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
891 llvm_unreachable("unknown relocation");
874892 }
875893}
876894
deps/lld/ELF/InputFiles.cpp+2-2
......@@ -1144,7 +1144,7 @@ void ArchiveFile::fetch(const Archive::Symbol &sym) {
11441144 Archive::Child c =
11451145 CHECK(sym.getMember(), toString(this) +
11461146 ": could not get the member for symbol " +
1147 sym.getName());
1147 toELFString(sym));
11481148
11491149 if (!seen.insert(c.getChildOffset()).second)
11501150 return;
......@@ -1153,7 +1153,7 @@ void ArchiveFile::fetch(const Archive::Symbol &sym) {
11531153 CHECK(c.getMemoryBufferRef(),
11541154 toString(this) +
11551155 ": could not get the buffer for the member defining symbol " +
1156 sym.getName());
1156 toELFString(sym));
11571157
11581158 if (tar && c.getParent()->isThin())
11591159 tar->append(relativeToRoot(CHECK(c.getFullName(), this)), mb.getBuffer());
deps/lld/ELF/Symbols.cpp+18-11
......@@ -42,6 +42,20 @@ Defined *ElfSym::relaIpltEnd;
4242Defined *ElfSym::riscvGlobalPointer;
4343Defined *ElfSym::tlsModuleBase;
4444
45// Returns a symbol for an error message.
46static std::string demangle(StringRef symName) {
47 if (config->demangle)
48 if (Optional<std::string> s = demangleItanium(symName))
49 return *s;
50 return symName;
51}
52namespace lld {
53std::string toString(const Symbol &b) { return demangle(b.getName()); }
54std::string toELFString(const Archive::Symbol &b) {
55 return demangle(b.getName());
56}
57} // namespace lld
58
4559static uint64_t getSymVA(const Symbol &sym, int64_t &addend) {
4660 switch (sym.kind()) {
4761 case Symbol::DefinedKind: {
......@@ -250,12 +264,13 @@ void Symbol::fetch() const {
250264}
251265
252266MemoryBufferRef LazyArchive::getMemberBuffer() {
253 Archive::Child c = CHECK(
254 sym.getMember(), "could not get the member for symbol " + sym.getName());
267 Archive::Child c =
268 CHECK(sym.getMember(),
269 "could not get the member for symbol " + toELFString(sym));
255270
256271 return CHECK(c.getMemoryBufferRef(),
257272 "could not get the buffer for the member defining symbol " +
258 sym.getName());
273 toELFString(sym));
259274}
260275
261276uint8_t Symbol::computeBinding() const {
......@@ -331,14 +346,6 @@ void elf::maybeWarnUnorderableSymbol(const Symbol *sym) {
331346 report(": unable to order discarded symbol: ");
332347}
333348
334// Returns a symbol for an error message.
335std::string lld::toString(const Symbol &b) {
336 if (config->demangle)
337 if (Optional<std::string> s = demangleItanium(b.getName()))
338 return *s;
339 return b.getName();
340}
341
342349static uint8_t getMinVisibility(uint8_t va, uint8_t vb) {
343350 if (va == STV_DEFAULT)
344351 return vb;
deps/lld/ELF/Symbols.h+5-1
......@@ -33,7 +33,11 @@ class Undefined;
3333} // namespace elf
3434
3535std::string toString(const elf::Symbol &);
36std::string toString(const elf::InputFile *);
36
37// There are two different ways to convert an Archive::Symbol to a string:
38// One for Microsoft name mangling and one for Itanium name mangling.
39// Call the functions toCOFFString and toELFString, not just toString.
40std::string toELFString(const elf::Archive::Symbol &);
3741
3842namespace elf {
3943
deps/lld/ELF/Writer.cpp+14-12
......@@ -2230,25 +2230,27 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
22302230// same with its virtual address modulo the page size, so that the loader can
22312231// load executables without any address adjustment.
22322232static uint64_t computeFileOffset(OutputSection *os, uint64_t off) {
2233 // File offsets are not significant for .bss sections. By convention, we keep
2234 // section offsets monotonically increasing rather than setting to zero.
2235 if (os->type == SHT_NOBITS)
2236 return off;
2237
2238 // If the section is not in a PT_LOAD, we just have to align it.
2239 if (!os->ptLoad)
2240 return alignTo(off, os->alignment);
2241
22422233 // The first section in a PT_LOAD has to have congruent offset and address
22432234 // module the page size.
2244 OutputSection *first = os->ptLoad->firstSec;
2245 if (os == first) {
2246 uint64_t alignment = std::max<uint64_t>(os->alignment, config->maxPageSize);
2235 if (os->ptLoad && os->ptLoad->firstSec == os) {
2236 uint64_t alignment =
2237 std::max<uint64_t>(os->ptLoad->p_align, config->maxPageSize);
22472238 return alignTo(off, alignment, os->addr);
22482239 }
22492240
2241 // File offsets are not significant for .bss sections other than the first one
2242 // in a PT_LOAD. By convention, we keep section offsets monotonically
2243 // increasing rather than setting to zero.
2244 if (os->type == SHT_NOBITS)
2245 return off;
2246
2247 // If the section is not in a PT_LOAD, we just have to align it.
2248 if (!os->ptLoad)
2249 return alignTo(off, os->alignment);
2250
22502251 // If two sections share the same PT_LOAD the file offset is calculated
22512252 // using this formula: Off2 = Off1 + (VA2 - VA1).
2253 OutputSection *first = os->ptLoad->firstSec;
22522254 return first->offset + os->addr - first->addr;
22532255}
22542256
deps/lld/docs/ReleaseNotes.rst+165-35
......@@ -5,18 +5,15 @@ lld 9.0.0 Release Notes
55.. contents::
66 :local:
77
8.. warning::
9 These are in-progress notes for the upcoming LLVM 9.0.0 release.
10 Release notes for previous releases can be found on
11 `the Download Page <https://releases.llvm.org/download.html>`_.
12
138Introduction
149============
1510
16This document contains the release notes for the lld linker, release 9.0.0.
17Here we describe the status of lld, including major improvements
18from the previous release. All lld releases may be downloaded
19from the `LLVM releases web site <https://llvm.org/releases/>`_.
11lld is a high-performance linker that supports ELF (Unix), COFF
12(Windows), Mach-O (macOS), MinGW and WebAssembly. lld is
13command-line-compatible with GNU linkers and Microsoft link.exe and is
14significantly faster than the system default linkers.
15
16lld 9 has lots of feature improvements and bug fixes.
2017
2118Non-comprehensive list of changes in this release
2219=================================================
......@@ -27,50 +24,187 @@ ELF Improvements
2724* ld.lld now has typo suggestions for flags:
2825 ``$ ld.lld --call-shared`` now prints
2926 ``unknown argument '--call-shared', did you mean '--call_shared'``.
27 (`r361518 <https://reviews.llvm.org/rL361518>`_)
28
29* ``--allow-shlib-undefined`` and ``--no-allow-shlib-undefined``
30 options are added. ``--no-allow-shlib-undefined`` is the default for
31 executables.
32 (`r352826 <https://reviews.llvm.org/rL352826>`_)
33
34* ``-nmagic`` and ``-omagic`` options are fully supported.
35 (`r360593 <https://reviews.llvm.org/rL360593>`_)
36
37* Segment layout has changed. PT_GNU_RELRO, which was previously
38 placed in the middle of readable/writable PT_LOAD segments, is now
39 placed at the beginning of them. This change permits lld-produced
40 ELF files to be read correctly by GNU strip older than 2.31, which
41 has a bug to discard a PT_GNU_RELRO in the former layout.
42
43* ``-z common-page-size`` is supported.
44 (`r360593 <https://reviews.llvm.org/rL360593>`_)
45
46* Diagnostics messages have improved. A new flag ``--vs-diagnostics``
47 alters the format of diagnostic output to enable source hyperlinks
48 in Microsoft Visual Studio IDE.
49
50* Linker script compatibility with GNU BFD linker has generally improved.
51
52* The clang ``--dependent-library`` form of autolinking is supported.
53
54 This feature is added to implement the Windows-style autolinking for
55 Unix. On Unix, in order to use a library, you usually have to
56 include a header file provided by the library and then explicitly
57 link the library with the linker ``-l`` option. On Windows, header
58 files usually contain pragmas that list needed libraries. Compilers
59 copy that information to object files, so that linkers can
60 automatically link needed libraries. ``--dependent-library`` is
61 added for implementing that Windows semantics on Unix.
62 (`r360984 <https://reviews.llvm.org/rL360984>`_)
63
64* AArch64 BTI and PAC are supported.
65 (`r362793 <https://reviews.llvm.org/rL362793>`_)
3066
3167* lld now supports replacing ``JAL`` with ``JALX`` instructions in case
32 of MIPS - microMIPS cross-mode jumps.
68 of MIPS-microMIPS cross-mode jumps.
69 (`r354311 <https://reviews.llvm.org/rL354311>`_)
3370
3471* lld now creates LA25 thunks for MIPS R6 code.
72 (`r354312 <https://reviews.llvm.org/rL354312>`_)
3573
3674* Put MIPS-specific .reginfo, .MIPS.options, and .MIPS.abiflags sections
3775 into corresponding PT_MIPS_REGINFO, PT_MIPS_OPTIONS, and PT_MIPS_ABIFLAGS
3876 segments.
3977
40* ...
78* The quality of RISC-V and PowerPC ports have greatly improved. Many
79 applications can now be linked by lld. PowerPC64 is now almost
80 production ready.
81
82* The Linux kernel for arm32_7, arm64, ppc64le and x86_64 can now be
83 linked by lld.
84
85* x86-64 TLSDESC is supported.
86 (`r361911 <https://reviews.llvm.org/rL361911>`_,
87 `r362078 <https://reviews.llvm.org/rL362078>`_)
88
89* DF_STATIC_TLS flag is set for i386 and x86-64 when needed.
90 (`r353293 <https://reviews.llvm.org/rL353293>`_,
91 `r353378 <https://reviews.llvm.org/rL353378>`_)
92
93* The experimental partitioning feature is added to allow a program to
94 be split into multiple pieces.
95
96 The feature allows you to semi-automatically split a single program
97 into multiple ELF files called "partitions". Since all partitions
98 share the same memory address space and don't use PLT/GOT, split
99 programs run as fast as regular programs.
100
101 With the mechanism, you can start a program only with a "main"
102 partition and load remaining partitions on-demand. For example, you
103 can split a web browser into a main partition and a PDF reader
104 sub-partition and load the PDF reader partition only when a user
105 tries to open a PDF file.
106
107 See `the documentation <Partitions.html>`_ for more information.
108
109* If "-" is given as an output filename, lld writes the final result
110 to the standard output. Previously, it created a file "-" in the
111 current directory.
112 (`r351852 <https://reviews.llvm.org/rL351852>`_)
113
114* ``-z ifunc-noplt`` option is added to reduce IFunc function call
115 overhead in a freestanding environment such as the OS kernel.
116
117 Functions resolved by the IFunc mechanism are usually dispatched via
118 PLT and thus slower than regular functions because of the cost of
119 indirection. With ``-z ifunc-noplt``, you can eliminate it by doing
120 text relocations at load-time. You need a special loader to utilize
121 this feature. This feature is added for the FreeBSD kernel but can
122 be used by any operating systems.
123 (`r360685 <https://reviews.llvm.org/rL360685>`_)
124
125* ``--undefined-glob`` option is added. The new option is an extension
126 to ``--undefined`` to take a glob pattern instead of a single symbol
127 name.
128 (`r363396 <https://reviews.llvm.org/rL363396>`_)
129
41130
42131COFF Improvements
43132-----------------
44133
45134* Like the ELF driver, lld-link now has typo suggestions for flags.
135 (`r361518 <https://reviews.llvm.org/rL361518>`_)
46136
47* lld-link now correctly reports duplicate symbol errors for obj files
48 that were compiled with /Gy.
137* lld-link now correctly reports duplicate symbol errors for object
138 files that were compiled with ``/Gy``.
139 (`r352590 <https://reviews.llvm.org/rL352590>`_)
49140
50* lld-link now correctly reports duplicate symbol errors when several res
51 input files define resources with the same type, name, and language.
52 This can be demoted to a warning using ``/force:multipleres``.
141* lld-link now correctly reports duplicate symbol errors when several
142 resource (.res) input files define resources with the same type,
143 name and language. This can be demoted to a warning using
144 ``/force:multipleres``.
145 (`r359829 <https://reviews.llvm.org/rL359829>`_)
146
147* lld-link now rejects more than one resource object input files,
148 matching link.exe. Previously, lld-link would silently ignore all
149 but one. If you hit this: Don't pass resource object files to the
150 linker, instead pass res files to the linker directly. Don't put
151 resource files in static libraries, pass them on the command line.
152 (`r359749 <https://reviews.llvm.org/rL359749>`_)
53153
54154* Having more than two ``/natvis:`` now works correctly; it used to not
55155 work for larger binaries before.
156 (`r327895 <https://reviews.llvm.org/rL327895>`_)
56157
57158* Undefined symbols are now printed only in demangled form. Pass
58159 ``/demangle:no`` to see raw symbol names instead.
59
60* The following flags have been added: ``/functionpadmin``, ``/swaprun:``,
61 ``/threads:no``
160 (`r355878 <https://reviews.llvm.org/rL355878>`_)
62161
63162* Several speed and memory usage improvements.
64163
65* Range extension thunks are now created for ARM64, if needed
66
67164* lld-link now supports resource object files created by GNU windres and
68 MS cvtres, not only llvm-cvtres
165 MS cvtres, not only llvm-cvtres.
69166
70167* The generated thunks for delayimports now share the majority of code
71 among thunks, significantly reducing the overhead of using delayimport
168 among thunks, significantly reducing the overhead of using delayimport.
169 (`r365823 <https://reviews.llvm.org/rL365823>`_)
170
171* ``IMAGE_REL_ARM{,64}_REL32`` relocations are supported.
172 (`r352325 <https://reviews.llvm.org/rL352325>`_)
173
174* Range extension thunks for AArch64 are now supported, so lld can
175 create large executables for Windows/ARM64.
176 (`r352929 <https://reviews.llvm.org/rL352929>`_)
177
178* The following flags have been added:
179 ``/functionpadmin`` (`r354716 <https://reviews.llvm.org/rL354716>`_),
180 ``/swaprun:`` (`r359192 <https://reviews.llvm.org/rL359192>`_),
181 ``/threads:no`` (`r355029 <https://reviews.llvm.org/rL355029>`_),
182 ``/filealign`` (`r361634 <https://reviews.llvm.org/rL361634>`_)
183
184WebAssembly Improvements
185------------------------
186
187* Imports from custom module names are supported.
188 (`r352828 <https://reviews.llvm.org/rL352828>`_)
189
190* Symbols that are in llvm.used are now exported by default.
191 (`r353364 <https://reviews.llvm.org/rL353364>`_)
192
193* Initial support for PIC and dynamic linking has landed.
194 (`r357022 <https://reviews.llvm.org/rL357022>`_)
195
196* wasm-ld now add ``__start_``/``__stop_`` symbols for data sections.
197 (`r361236 <https://reviews.llvm.org/rL361236>`_)
198
199* wasm-ld now doesn't report an error on archives without a symbol index.
200 (`r364338 <https://reviews.llvm.org/rL364338>`_)
201
202* The following flags have been added:
203 ``--emit-relocs`` (`r361635 <https://reviews.llvm.org/rL361635>`_),
204 ``--wrap`` (`r361639 <https://reviews.llvm.org/rL361639>`_),
205 ``--trace`` and ``--trace-symbol``
206 (`r353264 <https://reviews.llvm.org/rL353264>`_).
72207
73* ...
74208
75209MinGW Improvements
76210------------------
......@@ -80,22 +214,18 @@ MinGW Improvements
80214 DWARF exception handling with libgcc and gcc's crtend.o.
81215
82216* lld now also handles DWARF unwind info generated by GCC, when linking
83 with libgcc
84
85* Many more GNU ld options are now supported, which e.g. allows the lld
86 MinGW frontend to be called by GCC
217 with libgcc.
87218
88219* PDB output can be requested without manually specifying the PDB file
89220 name, with the new option ``-pdb=`` with an empty value to the option.
90221 (The old existing syntax ``-pdb <filename>`` was more cumbersome to use
91222 with an empty parameter value.)
92223
93MachO Improvements
94------------------
95
96* Item 1.
224* ``--no-insert-timestamp`` option is added as an alias to ``/timestamp:0``.
225 (`r353145 <https://reviews.llvm.org/rL353145>`_)
97226
98WebAssembly Improvements
99------------------------
227* Many more GNU ld options are now supported, which e.g. allows the lld
228 MinGW frontend to be called by GCC.
100229
101* ...
230* The following options are added: ``--exclude-all-symbols``,
231 ``--appcontainer``, ``--undefined``
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/test/COFF/Inputs/libcall-archive.ll created+6
......@@ -0,0 +1,6 @@
1target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
2target triple = "i686-unknown-windows"
3
4define void @memcpy() {
5 ret void
6}
deps/lld/test/COFF/Inputs/libcall-archive.s created+2
......@@ -0,0 +1,2 @@
1.globl ___sync_val_compare_and_swap_8
2___sync_val_compare_and_swap_8:
deps/lld/test/COFF/align.s created+45
......@@ -0,0 +1,45 @@
1# RUN: yaml2obj < %s > %t.obj
2# RUN: lld-link /out:%t.exe /entry:main /align:32 %t.obj
3# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s
4
5# CHECK: SectionAlignment: 32
6
7--- !COFF
8header:
9 Machine: IMAGE_FILE_MACHINE_AMD64
10 Characteristics: []
11sections:
12 - Name: .text
13 Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
14 Alignment: 4096
15 SectionData: 0000000000000000
16 Relocations:
17 - VirtualAddress: 0
18 SymbolName: __ImageBase
19 Type: IMAGE_REL_AMD64_ADDR64
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: 8
29 NumberOfRelocations: 1
30 NumberOfLinenumbers: 0
31 CheckSum: 0
32 Number: 0
33 - Name: main
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 - Name: __ImageBase
40 Value: 0
41 SectionNumber: 0
42 SimpleType: IMAGE_SYM_TYPE_NULL
43 ComplexType: IMAGE_SYM_DTYPE_NULL
44 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
45...
deps/lld/test/COFF/libcall-archive.ll created+22
......@@ -0,0 +1,22 @@
1; REQUIRES: x86
2; RUN: rm -f %t.a
3; RUN: llvm-as -o %t.obj %s
4; RUN: llvm-as -o %t2.obj %S/Inputs/libcall-archive.ll
5; RUN: llvm-mc -filetype=obj -triple=i686-unknown-windows -o %t3.obj %S/Inputs/libcall-archive.s
6; RUN: llvm-ar rcs %t.a %t2.obj %t3.obj
7; RUN: lld-link -out:%t.exe -subsystem:console -entry:start -safeseh:no -lldmap:- %t.obj %t.a | FileCheck %s
8
9; CHECK-NOT: ___sync_val_compare_and_swap_8
10; CHECK: _start
11; CHECK: _memcpy
12
13target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
14target triple = "i686-unknown-windows"
15
16define void @start(i8* %a, i8* %b) {
17entry:
18 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 1024, i1 false)
19 ret void
20}
21
22declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1)
deps/lld/test/COFF/multiple-resource-objs.test+2
......@@ -1,7 +1,9 @@
11# RUN: llvm-cvtres /out:%t_resource.obj %S/Inputs/resource.res
22# RUN: llvm-cvtres /out:%t_id.obj %S/Inputs/id.res
3# RUN: rm -f %t.exe
34# RUN: not lld-link /out:%t.exe /dll /noentry %t_id.obj %t_resource.obj 2>&1 | \
45# RUN: FileCheck --check-prefix=TWOOBJ %s
6# RUN: not test -f %t.exe
57
68TWOOBJ: error: {{.*}}_resource.obj: more than one resource obj file not allowed, already got {{.*}}_id.obj
79
deps/lld/test/COFF/thin-archive.s+6-2
......@@ -11,14 +11,18 @@
1111# RUN: FileCheck --allow-empty %s
1212# RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
1313# RUN: FileCheck --allow-empty %s
14# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \
15# RUN: FileCheck --allow-empty %s
1614
1715# RUN: rm %t.lib.obj
1816# RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
1917# RUN: FileCheck --allow-empty %s
18# RUN: not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
19# RUN: FileCheck --check-prefix=NOOBJ %s
20# RUN: not lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe \
21# RUN: /demangle:no 2>&1 | FileCheck --check-prefix=NOOBJNODEMANGLE %s
2022
2123# CHECK-NOT: error: could not get the buffer for the member defining
24# NOOBJ: error: could not get the buffer for the member defining symbol int __cdecl f(void): {{.*}}.lib({{.*}}.lib.obj):
25# NOOBJNODEMANGLE: error: could not get the buffer for the member defining symbol ?f@@YAHXZ: {{.*}}.lib({{.*}}.lib.obj):
2226
2327 .text
2428
deps/lld/test/ELF/archive-thin-missing-member.s+8-6
......@@ -8,17 +8,19 @@
88# RUN: rm %t.o
99
1010# Test error when loading symbols from missing thin archive member.
11# RUN: not ld.lld %t-no-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR1
11# RUN: not ld.lld --entry=_Z1fi %t-no-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR1
1212# ERR1: {{.*}}-no-syms.a: could not get the buffer for a child of the archive: '{{.*}}.o': {{[Nn]}}o such file or directory
1313
1414# Test error when thin archive has symbol table but member is missing.
15# RUN: not ld.lld -m elf_amd64_fbsd %t-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
16# ERR2: {{.*}}-syms.a: could not get the buffer for the member defining symbol _start: '{{.*}}.o': {{[Nn]}}o such file or directory
15# RUN: not ld.lld --entry=_Z1fi -m elf_amd64_fbsd %t-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
16# ERR2: {{.*}}-syms.a: could not get the buffer for the member defining symbol f(int): '{{.*}}.o': {{[Nn]}}o such file or directory
17# RUN: not ld.lld --entry=_Z1fi --no-demangle -m elf_amd64_fbsd %t-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2MANGLE
18# ERR2MANGLE: {{.*}}-syms.a: could not get the buffer for the member defining symbol _Z1fi: '{{.*}}.o': {{[Nn]}}o such file or directory
1719
1820# Test error when thin archive is linked using --whole-archive but member is missing.
19# RUN: not ld.lld --whole-archive %t-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR3
21# RUN: not ld.lld --entry=_Z1fi --whole-archive %t-syms.a -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR3
2022# ERR3: {{.*}}-syms.a: could not get the buffer for a child of the archive: '{{.*}}.o': {{[Nn]}}o such file or directory
2123
22.global _start
23_start:
24.global _Z1fi
25_Z1fi:
2426 nop
deps/lld/test/ELF/basic-ppc64.s+6-6
......@@ -35,7 +35,7 @@
3535// CHECK-NEXT: Version: 1
3636// CHECK-NEXT: Entry: 0x10000
3737// CHECK-NEXT: ProgramHeaderOffset: 0x40
38// CHECK-NEXT: SectionHeaderOffset: 0x200F8
38// CHECK-NEXT: SectionHeaderOffset: 0x30098
3939// CHECK-NEXT: Flags [ (0x2)
4040// CHECK-NEXT: 0x2
4141// CHECK-NEXT: ]
......@@ -178,7 +178,7 @@
178178// CHECK-NEXT: SHF_WRITE (0x1)
179179// CHECK-NEXT: ]
180180// CHECK-NEXT: Address: 0x30000
181// CHECK-NEXT: Offset: 0x20060
181// CHECK-NEXT: Offset: 0x30000
182182// CHECK-NEXT: Size: 0
183183// CHECK-NEXT: Link: 0
184184// CHECK-NEXT: Info: 0
......@@ -194,7 +194,7 @@
194194// CHECK-NEXT: SHF_STRINGS (0x20)
195195// CHECK-NEXT: ]
196196// CHECK-NEXT: Address: 0x0
197// CHECK-NEXT: Offset: 0x20060
197// CHECK-NEXT: Offset: 0x30000
198198// CHECK-NEXT: Size: 8
199199// CHECK-NEXT: Link: 0
200200// CHECK-NEXT: Info: 0
......@@ -211,7 +211,7 @@
211211// CHECK-NEXT: Flags [ (0x0)
212212// CHECK-NEXT: ]
213213// CHECK-NEXT: Address: 0x0
214// CHECK-NEXT: Offset: 0x20068
214// CHECK-NEXT: Offset: 0x30008
215215// CHECK-NEXT: Size: 48
216216// CHECK-NEXT: Link: 10
217217// CHECK-NEXT: Info: 2
......@@ -233,7 +233,7 @@
233233// CHECK-NEXT: Flags [ (0x0)
234234// CHECK-NEXT: ]
235235// CHECK-NEXT: Address: 0x0
236// CHECK-NEXT: Offset: 0x20098
236// CHECK-NEXT: Offset: 0x30038
237237// CHECK-NEXT: Size: 84
238238// CHECK-NEXT: Link: 0
239239// CHECK-NEXT: Info: 0
......@@ -255,7 +255,7 @@
255255// CHECK-NEXT: Flags [ (0x0)
256256// CHECK-NEXT: ]
257257// CHECK-NEXT: Address: 0x0
258// CHECK-NEXT: Offset: 0x200EC
258// CHECK-NEXT: Offset: 0x3008C
259259// CHECK-NEXT: Size: 10
260260// CHECK-NEXT: Link: 0
261261// CHECK-NEXT: Info: 0
deps/lld/test/ELF/linkerscript/nobits-offset.s+16-9
......@@ -2,17 +2,24 @@
22# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
33# RUN: echo "SECTIONS { \
44# RUN: .sec1 (NOLOAD) : { . += 1; } \
5# RUN: .text : { *(.text) } \
5# RUN: .bss : { *(.bss) } \
66# RUN: };" > %t.script
77# RUN: ld.lld %t.o -T %t.script -o %t
8# RUN: llvm-readelf --sections %t | FileCheck %s
8# RUN: llvm-readelf -S -l %t | FileCheck %s
99
10# We used to misalign section offsets if the first section in a
11# PT_LOAD was SHT_NOBITS.
10## If a SHT_NOBITS section is the only section of a PT_LOAD segment,
11## p_offset will be set to the sh_offset field of the section. Check we align
12## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod
13## p_align).
1214
13# CHECK: [ 2] .text PROGBITS 0000000000000010 001010 000010 00 AX 0 0 16
15# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
16# CHECK: .bss NOBITS 0000000000000400 001400 000001 00 WA 0 0 1024
1417
15.global _start
16_start:
17 nop
18.p2align 4
18# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
19# CHECK: LOAD 0x001400 0x0000000000000400 0x0000000000000400 0x000000 0x000001 RW 0x1000
20
21# CHECK: 00 .bss
22
23.bss
24.p2align 10
25.byte 0
deps/lld/test/ELF/nmagic.s created+23
......@@ -0,0 +1,23 @@
1# REQUIRES: x86
2# Verify that .rodata is aligned to a 8 byte boundary.
3
4# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o
5# RUN: ld.lld %t.o -o %t.exe -n -Ttext 0
6# RUN: llvm-readelf --section-headers %t.exe | FileCheck %s
7
8# CHECK: [ 0] NULL 00000000 000000 000000 00 0 0 0
9# CHECK: [ 1] .text PROGBITS 00000000 0000d4 000001 00 AX 0 0 4
10# CHECK: [ 2] .rodata PROGBITS 00000008 0000d8 000008 00 A 0 0 8
11# CHECK: [ 3] .comment PROGBITS 00000000 0000e0 000008 01 MS 0 0 1
12# CHECK: [ 4] .symtab SYMTAB 00000000 0000e8 000020 10 6 1 4
13# CHECK: [ 5] .shstrtab STRTAB 00000000 000108 000032 00 0 0 1
14# CHECK: [ 6] .strtab STRTAB 00000000 00013a 000008 00 0 0 1
15
16.globl _start
17.text
18_start:
19 ret
20
21.rodata
22.align 8
23.quad 42
deps/lld/test/ELF/nobits-offset.s created+21
......@@ -0,0 +1,21 @@
1# REQUIRES: aarch64
2# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
3# RUN: ld.lld %t.o -o %t
4# RUN: llvm-readelf -S -l %t | FileCheck %s
5
6## If a SHT_NOBITS section is the only section of a PT_LOAD segment,
7## p_offset will be set to the sh_offset field of the section. Check we align
8## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod
9## p_align).
10
11# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
12# CHECK: .bss NOBITS 0000000000210000 010000 000001 00 WA 0 0 4096
13
14# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
15# CHECK: LOAD 0x010000 0x0000000000210000 0x0000000000210000 0x000000 0x000001 RW 0x10000
16
17# CHECK: 02 .bss
18
19.bss
20.p2align 12
21.byte 0
deps/lld/test/ELF/ppc64-reloc-rel.s created+58
......@@ -0,0 +1,58 @@
1# REQUIRES: ppc
2
3# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
4# RUN: ld.lld %t.o --defsym=foo=rel16+0x8000 -o %t
5# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
6# RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=REL %s
7# RUN: llvm-readelf -S %t | FileCheck --check-prefix=SEC %s
8# RUN: llvm-readelf -x .eh_frame %t | FileCheck --check-prefix=HEX %s
9
10.section .R_PPC64_REL14,"ax",@progbits
11# FIXME This does not produce a relocation
12 beq 1f
131:
14# CHECK-LABEL: Disassembly of section .R_PPC64_REL14:
15# CHECK: bt 2, .+4
16
17.section .R_PPC64_REL16,"ax",@progbits
18.globl rel16
19rel16:
20 li 3, foo-rel16-1@ha # R_PPC64_REL16_HA
21 li 3, foo-rel16@ha
22 li 4, foo-rel16+0x7fff@h # R_PPC64_REL16_HI
23 li 4, foo-rel16+0x8000@h
24 li 5, foo-rel16-1@l # R_PPC64_REL16_LO
25 li 5, foo-rel16@l
26# CHECK-LABEL: Disassembly of section .R_PPC64_REL16:
27# CHECK: li 3, 0
28# CHECK-NEXT: li 3, 1
29# CHECK-NEXT: li 4, 0
30# CHECK-NEXT: li 4, 1
31# CHECK-NEXT: li 5, 32767
32# CHECK-NEXT: li 5, -32768
33
34.section .R_PPC64_REL24,"ax",@progbits
35 b rel16
36# CHECK-LABEL: Disassembly of section .R_PPC64_REL24:
37# CHECK: b .+67108840
38
39.section .REL32_AND_REL64,"ax",@progbits
40 .cfi_startproc
41 .cfi_personality 148, rel64
42 nop
43 .cfi_endproc
44rel64:
45 li 3, 0
46# REL: .rela.eh_frame {
47# REL-NEXT: 0x12 R_PPC64_REL64 .REL32_AND_REL64 0x4
48# REL-NEXT: 0x28 R_PPC64_REL32 .REL32_AND_REL64 0x0
49# REL-NEXT: }
50
51# SEC: .REL32_AND_REL64 PROGBITS 0000000010010020
52
53## CIE Personality Address: 0x10010020-(0x10000168+2)+4 = 0xfeba
54## FDE PC Begin: 0x10010020-(0x10000178+8) = 0xfea0
55# HEX: section '.eh_frame':
56# HEX-NEXT: 0x10000158
57# HEX-NEXT: 0x10000168 {{....}}bafe 00000000
58# HEX-NEXT: 0x10000178 {{[0-9a-f]+}} {{[0-9a-f]+}} a0fe0000
deps/lld/test/ELF/ppc64-relocs.s+9-72
......@@ -18,16 +18,9 @@ _start:
1818 li 3,42
1919 sc
2020
21.section .rodata,"a",@progbits
22 .p2align 2
23.LJTI0_0:
24 .long .LBB0_2-.LJTI0_0
25
26.section .toc,"aw",@progbits
21.section .toc,"aw",@progbits
2722.L1:
28.quad 22, 37, 89, 47
29.LC0:
30 .tc .LJTI0_0[TC],.LJTI0_0
23 .quad 22, 37, 89, 47
3124
3225.section .R_PPC64_TOC16_LO_DS,"ax",@progbits
3326 ld 1, .L1@toc@l(2)
......@@ -53,91 +46,47 @@ _start:
5346# CHECK-LABEL: Disassembly of section .R_PPC64_TOC16_HA:
5447# CHECK: 10010018: addis 1, 2, 0
5548
56.section .R_PPC64_REL24,"ax",@progbits
57 b 1f
581:
59
60# CHECK-LABEL: Disassembly of section .R_PPC64_REL24:
61# CHECK: 1001001c: b .+4
62
63.section .R_PPC64_REL14,"ax",@progbits
64 beq 1f
651:
66
67# CHECK-LABEL: Disassembly of section .R_PPC64_REL14:
68# CHECK: 10010020: bt 2, .+4
69
7049.section .R_PPC64_ADDR16_LO,"ax",@progbits
7150 li 1, .Lfoo@l
7251
7352# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_LO:
74# CHECK: 10010024: li 1, 0
53# CHECK: li 1, 0
7554
7655.section .R_PPC64_ADDR16_HI,"ax",@progbits
7756 li 1, .Lfoo@h
7857
7958# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HI:
80# CHECK: 10010028: li 1, 4097
59# CHECK: li 1, 4097
8160
8261.section .R_PPC64_ADDR16_HA,"ax",@progbits
8362 li 1, .Lfoo@ha
8463
8564# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HA:
86# CHECK: 1001002c: li 1, 4097
65# CHECK: li 1, 4097
8766
8867.section .R_PPC64_ADDR16_HIGHER,"ax",@progbits
8968 li 1, .Lfoo@higher
9069
9170# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHER:
92# CHECK: 10010030: li 1, 0
71# CHECK: li 1, 0
9372
9473.section .R_PPC64_ADDR16_HIGHERA,"ax",@progbits
9574 li 1, .Lfoo@highera
9675
9776# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHERA:
98# CHECK: 10010034: li 1, 0
77# CHECK: li 1, 0
9978
10079.section .R_PPC64_ADDR16_HIGHEST,"ax",@progbits
10180 li 1, .Lfoo@highest
10281
10382# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHEST:
104# CHECK: 10010038: li 1, 0
83# CHECK: li 1, 0
10584
10685.section .R_PPC64_ADDR16_HIGHESTA,"ax",@progbits
10786 li 1, .Lfoo@highesta
10887
10988# CHECK-LABEL: Disassembly of section .R_PPC64_ADDR16_HIGHESTA:
110# CHECK: 1001003c: li 1, 0
111
112.section .R_PPC64_REL32, "ax",@progbits
113 addis 5, 2, .LC0@toc@ha
114 ld 5, .LC0@toc@l(5)
115.LBB0_2:
116 add 3, 3, 4
117
118# DATALE: '.rodata':
119# DATALE: 0x100001c8 80fe0000
120
121# DATABE: '.rodata':
122# DATABE: 0x100001c8 0000fe80
123
124# Address of rodata + value stored at rodata entry
125# should equal address of LBB0_2.
126# 0x10000190 + 0xfeb4 = 0x10010044
127# CHECK-LABEL: Disassembly of section .R_PPC64_REL32:
128# CHECK: 10010040: addis 5, 2, 0
129# CHECK: 10010044: ld 5, -32736(5)
130# CHECK: 10010048: add 3, 3, 4
131
132.section .R_PPC64_REL64, "ax",@progbits
133 .cfi_startproc
134 .cfi_personality 148, __foo
135 li 0, 1
136 li 3, 55
137 sc
138 .cfi_endproc
139__foo:
140 li 3,0
89# CHECK: li 1, 0
14190
14291.section .R_PPC64_TOC,"a",@progbits
14392 .quad .TOC.@tocbase
......@@ -150,15 +99,3 @@ __foo:
15099
151100# DATABE-LABEL: section '.R_PPC64_TOC':
152101# DATABE: 00000000 10028000
153
154# Check that the personality (relocated by R_PPC64_REL64) in the .eh_frame
155# equals the address of __foo.
156# 0x100001ea + 0xfe6e = 0x10010058
157# DATALE: section '.eh_frame':
158# DATALE: 0x100001e8 {{....}}6efe
159
160# DATABE: section '.eh_frame':
161# DATABE: 0x100001e8 {{[0-9a-f]+ [0-9a-f]+}} fe6e{{....}}
162
163# CHECK: __foo
164# CHECK-NEXT: 10010058: li 3, 0
deps/lld/test/ELF/relocation-copy-align-common.s+1-1
......@@ -15,7 +15,7 @@
1515# CHECK-NEXT: SHF_WRITE
1616# CHECK-NEXT: ]
1717# CHECK-NEXT: Address: 0x203000
18# CHECK-NEXT: Offset: 0x20B0
18# CHECK-NEXT: Offset: 0x3000
1919# CHECK-NEXT: Size: 16
2020# CHECK-NEXT: Link: 0
2121# CHECK-NEXT: Info: 0