Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 250bfb1

Browse files
committed
Remove the LLVM specific archive index.
Archive files (.a) can have a symbol table indicating which object files in them define which symbols. The purpose of this symbol table is to speed up linking by allowing the linker the read only the .o files it is actually going to use instead of having to parse every object's symbol table. LLVM's archive library currently supports a LLVM specific format for such table. It is hard to see any value in that now that llvm-ld is gone: * System linkers don't use it: GNU ar uses the same plugin as the linker to create archive files with a regular index. The OS X ar creates no symbol table for IL files, I assume the linker just parses all IL files. * It doesn't interact well with archives having both IL and native objects. * We probably don't want to be responsible for yet another archive format variant. This patch then: * Removes support for creating and reading such index from lib/Archive. * Remove llvm-ranlib, since there is nothing left for it to do. We should in the future add support for regular indexes to llvm-ar for both native and IL objects. When we do that, llvm-ranlib should be reimplemented as a symlink to llvm-ar, as it is equivalent to "ar s". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184019 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d605526 commit 250bfb1

19 files changed

+19
-391
lines changed

docs/CommandGuide/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Basic Commands
2121
lli
2222
llvm-link
2323
llvm-ar
24-
llvm-ranlib
2524
llvm-nm
2625
llvm-prof
2726
llvm-config

docs/CommandGuide/llvm-ar.rst

+2-11
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ The modifiers below may be applied to any operation.
283283
This modifier requests that an archive index (or symbol table) be added to the
284284
archive. This is the default mode of operation. The symbol table will contain
285285
all the externally visible functions and global variables defined by all the
286-
bitcode files in the archive. Using this modifier is more efficient that using
287-
llvm-ranlib|llvm-ranlib which also creates the symbol table.
286+
bitcode files in the archive.
288287

289288

290289

@@ -401,14 +400,6 @@ fmag - char[2]
401400
utility in identifying archive files that have been corrupted.
402401

403402

404-
405-
The LLVM symbol table has the special name "#_LLVM_SYM_TAB_#". It is presumed
406-
that no regular archive member file will want this name. The LLVM symbol table
407-
is simply composed of a sequence of triplets: byte offset, length of symbol,
408-
and the symbol itself. Symbols are not null or newline terminated. Here are
409-
the details on each of these items:
410-
411-
412403
offset - vbr encoded 32-bit integer
413404

414405
The offset item provides the offset into the archive file where the bitcode
@@ -455,4 +446,4 @@ SEE ALSO
455446
--------
456447

457448

458-
llvm-ranlib|llvm-ranlib, ar(1)
449+
ar(1)

docs/CommandGuide/llvm-ranlib.rst

-61
This file was deleted.

include/llvm/Bitcode/Archive.h

+4-19
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
5050
enum Flags {
5151
SVR4SymbolTableFlag = 1, ///< Member is a SVR4 symbol table
5252
BSD4SymbolTableFlag = 2, ///< Member is a BSD4 symbol table
53-
LLVMSymbolTableFlag = 4, ///< Member is an LLVM symbol table
54-
BitcodeFlag = 8, ///< Member is bitcode
55-
HasPathFlag = 16, ///< Member has a full or partial path
56-
HasLongFilenameFlag = 32, ///< Member uses the long filename syntax
57-
StringTableFlag = 64 ///< Member is an ar(1) format string table
53+
BitcodeFlag = 4, ///< Member is bitcode
54+
HasPathFlag = 8, ///< Member has a full or partial path
55+
HasLongFilenameFlag = 16, ///< Member uses the long filename syntax
56+
StringTableFlag = 32 ///< Member is an ar(1) format string table
5857
};
5958

6059
/// @}
@@ -117,10 +116,6 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
117116
/// @brief Determine if this member is a BSD4.4 symbol table.
118117
bool isBSD4SymbolTable() const { return flags&BSD4SymbolTableFlag; }
119118

120-
/// @returns true iff the archive member is the LLVM symbol table
121-
/// @brief Determine if this member is the LLVM symbol table.
122-
bool isLLVMSymbolTable() const { return flags&LLVMSymbolTableFlag; }
123-
124119
/// @returns true iff the archive member is the ar(1) string table
125120
/// @brief Determine if this member is the ar(1) string table.
126121
bool isStringTable() const { return flags&StringTableFlag; }
@@ -445,13 +440,6 @@ class Archive {
445440
/// into memory.
446441
explicit Archive(const sys::Path& filename, LLVMContext& C);
447442

448-
/// @param data The symbol table data to be parsed
449-
/// @param len The length of the symbol table data
450-
/// @param error Set to address of a std::string to get error messages
451-
/// @returns false on error
452-
/// @brief Parse the symbol table at \p data.
453-
bool parseSymbolTable(const void* data,unsigned len,std::string* error);
454-
455443
/// @returns A fully populated ArchiveMember or 0 if an error occurred.
456444
/// @brief Parse the header of a member starting at \p At
457445
ArchiveMember* parseMemberHeader(
@@ -475,9 +463,6 @@ class Archive {
475463
/// @brief Load just the symbol table.
476464
bool loadSymbolTable(std::string* ErrMessage);
477465

478-
/// @brief Write the symbol table to an ofstream.
479-
void writeSymbolTable(std::ofstream& ARFile);
480-
481466
/// Writes one ArchiveMember to an ofstream. If an error occurs, returns
482467
/// false, otherwise true. If an error occurs and error is non-null then
483468
/// it will be set to an error message.

lib/Archive/Archive.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
9090
else
9191
flags &= ~BSD4SymbolTableFlag;
9292

93-
// LLVM symbol tables have a very specific name
94-
if (path.str() == ARFILE_LLVM_SYMTAB_NAME)
95-
flags |= LLVMSymbolTableFlag;
96-
else
97-
flags &= ~LLVMSymbolTableFlag;
98-
9993
// String table name
10094
if (path.str() == ARFILE_STRTAB_NAME)
10195
flags |= StringTableFlag;

lib/Archive/ArchiveInternals.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#define ARFILE_MAGIC "!<arch>\n" ///< magic string
2323
#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
2424
#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
25-
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
2625
#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
2726
#define ARFILE_STRTAB_NAME "// " ///< Name of string table
2827
#define ARFILE_PAD "\n" ///< inter-file align padding

lib/Archive/ArchiveReader.cpp

+7-81
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,6 @@ static inline unsigned readInteger(const char*&At, const char*End) {
3737
return Result;
3838
}
3939

40-
// Completely parse the Archive's symbol table and populate symTab member var.
41-
bool
42-
Archive::parseSymbolTable(const void* data, unsigned size, std::string* error) {
43-
const char* At = (const char*) data;
44-
const char* End = At + size;
45-
while (At < End) {
46-
unsigned offset = readInteger(At, End);
47-
if (At == End) {
48-
if (error)
49-
*error = "Ran out of data reading vbr_uint for symtab offset!";
50-
return false;
51-
}
52-
unsigned length = readInteger(At, End);
53-
if (At == End) {
54-
if (error)
55-
*error = "Ran out of data reading vbr_uint for symtab length!";
56-
return false;
57-
}
58-
if (At + length > End) {
59-
if (error)
60-
*error = "Malformed symbol table: length not consistent with size";
61-
return false;
62-
}
63-
// we don't care if it can't be inserted (duplicate entry)
64-
symTab.insert(std::make_pair(std::string(At, length), offset));
65-
At += length;
66-
}
67-
symTabSize = size;
68-
return true;
69-
}
70-
7140
// This member parses an ArchiveMemberHeader that is presumed to be pointed to
7241
// by At. The At pointer is updated to the byte just after the header, which
7342
// can be variable in size.
@@ -108,10 +77,8 @@ Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
10877
// for long file names. This library doesn't generate either of those but
10978
// it will accept them. If the name starts with #1/ and the remainder is
11079
// digits, then those digits specify the length of the name that is
111-
// stored immediately following the header. The special name
112-
// __LLVM_SYM_TAB__ identifies the symbol table for LLVM bitcode.
113-
// Anything else is a regular, short filename that is terminated with
114-
// a '/' and blanks.
80+
// stored immediately following the header. Anything else is a regular, short
81+
// filename that is terminated with a '/' and blanks.
11582

11683
std::string pathname;
11784
switch (Hdr->name[0]) {
@@ -129,16 +96,6 @@ Archive::parseMemberHeader(const char*& At, const char* End, std::string* error)
12996
*error = "invalid long filename";
13097
return 0;
13198
}
132-
} else if (Hdr->name[1] == '_' &&
133-
(0 == memcmp(Hdr->name, ARFILE_LLVM_SYMTAB_NAME, 16))) {
134-
// The member is using a long file name (>15 chars) format.
135-
// This format is standard for 4.4BSD and Mac OSX operating
136-
// systems. LLVM uses it similarly. In this format, the
137-
// remainder of the name field (after #1/) specifies the
138-
// length of the file name which occupy the first bytes of
139-
// the member's data. The pathname already has the #1/ stripped.
140-
pathname.assign(ARFILE_LLVM_SYMTAB_NAME);
141-
flags |= ArchiveMember::LLVMSymbolTableFlag;
14299
}
143100
break;
144101
case '/':
@@ -259,7 +216,6 @@ Archive::loadArchive(std::string* error) {
259216

260217
At += 8; // Skip the magic string.
261218

262-
bool seenSymbolTable = false;
263219
bool foundFirstFile = false;
264220
while (At < End) {
265221
// parse the member header
@@ -291,21 +247,6 @@ Archive::loadArchive(std::string* error) {
291247
if ((intptr_t(At) & 1) == 1)
292248
At++;
293249
delete mbr;
294-
} else if (mbr->isLLVMSymbolTable()) {
295-
// This is the LLVM symbol table for the archive. If we've seen it
296-
// already, its an error. Otherwise, parse the symbol table and move on.
297-
if (seenSymbolTable) {
298-
if (error)
299-
*error = "invalid archive: multiple symbol tables";
300-
return false;
301-
}
302-
if (!parseSymbolTable(mbr->getData(), mbr->getSize(), error))
303-
return false;
304-
seenSymbolTable = true;
305-
At += mbr->getSize();
306-
if ((intptr_t(At) & 1) == 1)
307-
At++;
308-
delete mbr; // We don't need this member in the list of members.
309250
} else {
310251
// This is just a regular file. If its the first one, save its offset.
311252
// Otherwise just push it on the list and move on to the next file.
@@ -412,26 +353,11 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
412353
}
413354
}
414355

415-
// See if its the symbol table
416-
if (mbr->isLLVMSymbolTable()) {
417-
if (!parseSymbolTable(mbr->getData(), mbr->getSize(), ErrorMsg)) {
418-
delete mbr;
419-
return false;
420-
}
421-
422-
At += mbr->getSize();
423-
if ((intptr_t(At) & 1) == 1)
424-
At++;
425-
delete mbr;
426-
// Can't be any more symtab headers so just advance
427-
FirstFile = At;
428-
} else {
429-
// There's no symbol table in the file. We have to rebuild it from scratch
430-
// because the intent of this method is to get the symbol table loaded so
431-
// it can be searched efficiently.
432-
// Add the member to the members list
433-
members.push_back(mbr);
434-
}
356+
// There's no symbol table in the file. We have to rebuild it from scratch
357+
// because the intent of this method is to get the symbol table loaded so
358+
// it can be searched efficiently.
359+
// Add the member to the members list
360+
members.push_back(mbr);
435361

436362
firstFileOffset = FirstFile - base;
437363
return true;

lib/Archive/ArchiveWriter.cpp

-60
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
113113
memcpy(hdr.name,ARFILE_SVR4_SYMTAB_NAME,16);
114114
} else if (mbr.isBSD4SymbolTable()) {
115115
memcpy(hdr.name,ARFILE_BSD4_SYMTAB_NAME,16);
116-
} else if (mbr.isLLVMSymbolTable()) {
117-
memcpy(hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
118116
} else if (TruncateNames) {
119117
const char* nm = mbrPath.c_str();
120118
unsigned len = mbrPath.length();
@@ -289,61 +287,6 @@ Archive::writeMember(
289287
return false;
290288
}
291289

292-
// Write out the LLVM symbol table as an archive member to the file.
293-
void
294-
Archive::writeSymbolTable(std::ofstream& ARFile) {
295-
296-
// Construct the symbol table's header
297-
ArchiveMemberHeader Hdr;
298-
Hdr.init();
299-
memcpy(Hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
300-
uint64_t secondsSinceEpoch = sys::TimeValue::now().toEpochTime();
301-
char buffer[32];
302-
sprintf(buffer, "%-8o", 0644);
303-
memcpy(Hdr.mode,buffer,8);
304-
sprintf(buffer, "%-6u", sys::Process::GetCurrentUserId());
305-
memcpy(Hdr.uid,buffer,6);
306-
sprintf(buffer, "%-6u", sys::Process::GetCurrentGroupId());
307-
memcpy(Hdr.gid,buffer,6);
308-
sprintf(buffer,"%-12u", unsigned(secondsSinceEpoch));
309-
memcpy(Hdr.date,buffer,12);
310-
sprintf(buffer,"%-10u",symTabSize);
311-
memcpy(Hdr.size,buffer,10);
312-
313-
// Write the header
314-
ARFile.write((char*)&Hdr, sizeof(Hdr));
315-
316-
#ifndef NDEBUG
317-
// Save the starting position of the symbol tables data content.
318-
unsigned startpos = ARFile.tellp();
319-
#endif
320-
321-
// Write out the symbols sequentially
322-
for ( Archive::SymTabType::iterator I = symTab.begin(), E = symTab.end();
323-
I != E; ++I)
324-
{
325-
// Write out the file index
326-
writeInteger(I->second, ARFile);
327-
// Write out the length of the symbol
328-
writeInteger(I->first.length(), ARFile);
329-
// Write out the symbol
330-
ARFile.write(I->first.data(), I->first.length());
331-
}
332-
333-
#ifndef NDEBUG
334-
// Now that we're done with the symbol table, get the ending file position
335-
unsigned endpos = ARFile.tellp();
336-
#endif
337-
338-
// Make sure that the amount we wrote is what we pre-computed. This is
339-
// critical for file integrity purposes.
340-
assert(endpos - startpos == symTabSize && "Invalid symTabSize computation");
341-
342-
// Make sure the symbol table is even sized
343-
if (symTabSize % 2 != 0 )
344-
ARFile << ARFILE_PAD;
345-
}
346-
347290
// Write the entire archive to the file specified when the archive was created.
348291
// This writes to a temporary file first. Options are for creating a symbol
349292
// table, flattening the file names (no directories, 15 chars max) and
@@ -453,9 +396,6 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
453396
}
454397
}
455398

456-
// Put out the LLVM symbol table now.
457-
writeSymbolTable(FinalFile);
458-
459399
// Copy the temporary file contents being sure to skip the file's magic
460400
// number.
461401
FinalFile.write(base + sizeof(ARFILE_MAGIC)-1,

lib/Object/Archive.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ static const char *Magic = "!<arch>\n";
2424
static bool isInternalMember(const ArchiveMemberHeader &amh) {
2525
static const char *const internals[] = {
2626
"/",
27-
"//",
28-
"#_LLVM_SYM_TAB_#"
27+
"//"
2928
};
3029

3130
StringRef name = amh.getName();

0 commit comments

Comments
 (0)