llvm.org GIT mirror llvm / 68806ff
Add support for Darwin’s static library table of contents with 64-bit offsets to the archive members. Darwin added support in its Xcode 8.0 tools (released in the beta) for static library table of contents with 64-bit offsets to the archive members. The change is very straight forward. The table of contents member is named ___.SYMDEF_64 or "___.SYMDEF_64 SORTED" and same layout is used but with fields using 64 bit values instead of 32 bit values. rdar://26869808 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273058 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 3 years ago
4 changed file(s) with 48 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
182182 K_GNU,
183183 K_MIPS64,
184184 K_BSD,
185 K_DARWIN64,
185186 K_COFF
186187 };
187188
224225 uint16_t FirstRegularStartOfFile = -1;
225226 void setFirstRegular(const Child &C);
226227
227 unsigned Format : 2;
228 unsigned Format : 3;
228229 unsigned IsThin : 1;
229230 mutable std::vector> ThinBuffers;
230231 };
329329 // seem to create the third member if there's no member whose filename
330330 // exceeds 15 characters. So the third member is optional.
331331
332 if (Name == "__.SYMDEF") {
333 Format = K_BSD;
332 if (Name == "__.SYMDEF" || Name == "__.SYMDEF_64") {
333 if (Name == "__.SYMDEF")
334 Format = K_BSD;
335 else // Name == "__.SYMDEF_64"
336 Format = K_DARWIN64;
334337 // We know that the symbol table is not an external file, so we just assert
335338 // there is no error.
336339 SymbolTable = *C->getBuffer();
357360 if (Increment())
358361 return;
359362 }
363 else if (Name == "__.SYMDEF_64 SORTED" || Name == "__.SYMDEF_64") {
364 Format = K_DARWIN64;
365 // We know that the symbol table is not an external file, so we just
366 // assert there is no error.
367 SymbolTable = *C->getBuffer();
368 if (Increment())
369 return;
370 }
360371 setFirstRegular(*C);
361372 return;
362373 }
461472 ErrorOr Archive::Symbol::getMember() const {
462473 const char *Buf = Parent->getSymbolTable().begin();
463474 const char *Offsets = Buf;
464 if (Parent->kind() == K_MIPS64)
475 if (Parent->kind() == K_MIPS64 || Parent->kind() == K_DARWIN64)
465476 Offsets += sizeof(uint64_t);
466477 else
467478 Offsets += sizeof(uint32_t);
478489 // the archive of the member that defines the symbol. Which is what
479490 // is needed here.
480491 Offset = read32le(Offsets + SymbolIndex * 8 + 4);
492 } else if (Parent->kind() == K_DARWIN64) {
493 // The SymbolIndex is an index into the ranlib_64 structs that start at
494 // Offsets (the first uint64_t is the number of bytes of the ranlib_64
495 // structs). The ranlib_64 structs are a pair of uint64_t's the first
496 // being a string table offset and the second being the offset into
497 // the archive of the member that defines the symbol. Which is what
498 // is needed here.
499 Offset = read64le(Offsets + SymbolIndex * 16 + 8);
481500 } else {
482501 // Skip offsets.
483502 uint32_t MemberCount = read32le(Buf);
577596 // Skip the byte count of the string table.
578597 buf += sizeof(uint32_t);
579598 buf += ran_strx;
599 } else if (kind() == K_DARWIN64) {
600 // The __.SYMDEF_64 or "__.SYMDEF_64 SORTED" member starts with a uint64_t
601 // which is the number of bytes of ranlib_64 structs that follow. The
602 // ranlib_64 structs are a pair of uint64_t's the first being a string
603 // table offset and the second being the offset into the archive of the
604 // member that define the symbol. After that the next uint64_t is the byte
605 // count of the string table followed by the string table.
606 uint64_t ranlib_count = 0;
607 ranlib_count = read64le(buf) / 16;
608 const char *ranlibs = buf + 8;
609 uint64_t ran_strx = 0;
610 ran_strx = read64le(ranlibs);
611 buf += sizeof(uint64_t) + (ranlib_count * (2 * (sizeof(uint64_t))));
612 // Skip the byte count of the string table.
613 buf += sizeof(uint64_t);
614 buf += ran_strx;
580615 } else {
581616 uint32_t member_count = 0;
582617 uint32_t symbol_count = 0;
603638 return read64be(buf);
604639 if (kind() == K_BSD)
605640 return read32le(buf) / 8;
641 if (kind() == K_DARWIN64)
642 return read64le(buf) / 16;
606643 uint32_t member_count = 0;
607644 member_count = read32le(buf);
608645 buf += 4 + (member_count * 4); // Skip offsets.
9898 MACHO-NEXT: 0000000000000001 T _foo
9999 MACHO-NEXT: 0000000000000002 T _main
100100
101 RUN: llvm-nm -M %p/Inputs/macho-toc64-archive-x86_64.a | FileCheck --check-prefix=MACHO-TOC64 %s
102
103 MACHO-TOC64: Archive map
104 MACHO-TOC64-NEXT: _test in test.o
105 MACHO-TOC64-NEXT: _test in xtest.o
106
101107 RUN: rm -f %t.a
102108 RUN: llvm-ar --format=gnu rcsU %t.a %p/Inputs/coff-short-import-code %p/Inputs/coff-short-import-data
103109 RUN: llvm-nm -M %t.a | FileCheck --check-prefix=COFF-SHORT-IMPORT %s