mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Distinguish between BSD4.4 and SVR4 symbol tables
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18044 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e651c954aa
commit
9a29db43a7
@ -49,12 +49,13 @@ class ArchiveMember {
|
||||
/// access to the flags. The flags are not user settable.
|
||||
enum Flags {
|
||||
CompressedFlag = 1, ///< Member is a normal compressed file
|
||||
ForeignSymbolTableFlag = 2, ///< Member is a foreign symbol table
|
||||
LLVMSymbolTableFlag = 4, ///< Member is an LLVM symbol table
|
||||
BytecodeFlag = 8, ///< Member is uncompressed bytecode
|
||||
CompressedBytecodeFlag = 16, ///< Member is compressed bytecode
|
||||
HasPathFlag = 32, ///< Member has a full or partial path
|
||||
HasLongFilenameFlag = 64, ///< Member uses the long filename syntax
|
||||
SVR4SymbolTableFlag = 2, ///< Member is a SVR4 symbol table
|
||||
BSD4SymbolTableFlag = 4, ///< Member is a BSD4 symbol table
|
||||
LLVMSymbolTableFlag = 8, ///< Member is an LLVM symbol table
|
||||
BytecodeFlag = 16, ///< Member is uncompressed bytecode
|
||||
CompressedBytecodeFlag = 32, ///< Member is compressed bytecode
|
||||
HasPathFlag = 64, ///< Member has a full or partial path
|
||||
HasLongFilenameFlag = 128, ///< Member uses the long filename syntax
|
||||
StringTableFlag = 256, ///< Member is an ar(1) format string table
|
||||
};
|
||||
|
||||
@ -117,9 +118,13 @@ class ArchiveMember {
|
||||
/// @brief Determine if the member is a compressed regular file.
|
||||
bool isCompressed() const { return flags&CompressedFlag; }
|
||||
|
||||
/// @returns true iff the member is a foreign (non-LLVM) symbol table
|
||||
/// @brief Determine if this member is a foreign symbol table.
|
||||
bool isForeignSymbolTable() const { return flags&ForeignSymbolTableFlag; }
|
||||
/// @returns true iff the member is a SVR4 (non-LLVM) symbol table
|
||||
/// @brief Determine if this member is a SVR4 symbol table.
|
||||
bool isSVR4SymbolTable() const { return flags&SVR4SymbolTableFlag; }
|
||||
|
||||
/// @returns true iff the member is a BSD4.4 (non-LLVM) symbol table
|
||||
/// @brief Determine if this member is a BSD4.4 symbol table.
|
||||
bool isBSD4SymbolTable() const { return flags&BSD4SymbolTableFlag; }
|
||||
|
||||
/// @returns true iff the archive member is the LLVM symbol table
|
||||
/// @brief Determine if this member is the LLVM symbol table.
|
||||
|
@ -65,11 +65,17 @@ void ArchiveMember::replaceWith(const sys::Path& newFile) {
|
||||
data = 0;
|
||||
path = newFile;
|
||||
|
||||
// Foreign symbol tables have an empty name
|
||||
if (path.get() == ARFILE_SYMTAB_NAME)
|
||||
flags |= ForeignSymbolTableFlag;
|
||||
// SVR4 symbol tables have an empty name
|
||||
if (path.get() == ARFILE_SVR4_SYMTAB_NAME)
|
||||
flags |= SVR4SymbolTableFlag;
|
||||
else
|
||||
flags &= ~ForeignSymbolTableFlag;
|
||||
flags &= ~SVR4SymbolTableFlag;
|
||||
|
||||
// BSD4.4 symbol tables have a special name
|
||||
if (path.get() == ARFILE_BSD4_SYMTAB_NAME)
|
||||
flags |= BSD4SymbolTableFlag;
|
||||
else
|
||||
flags &= ~BSD4SymbolTableFlag;
|
||||
|
||||
// LLVM symbol tables have a very specific name
|
||||
if (path.get() == ARFILE_LLVM_SYMTAB_NAME)
|
||||
|
@ -20,9 +20,10 @@
|
||||
|
||||
#define ARFILE_MAGIC "!<arch>\n" ///< magic string
|
||||
#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
|
||||
#define ARFILE_SYMTAB_NAME "/ " ///< regular symtab entry
|
||||
#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
|
||||
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
|
||||
#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
|
||||
#define ARFILE_STRTAB_NAME "// " ///< Name of string table
|
||||
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM's symtab entry
|
||||
#define ARFILE_PAD "\n" ///< inter-file align padding
|
||||
#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
|
||||
|
||||
|
@ -123,11 +123,11 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
|
||||
throw std::string("invalid string table name");
|
||||
}
|
||||
} else if (Hdr->name[1] == ' ') {
|
||||
if (0==memcmp(Hdr->name,ARFILE_SYMTAB_NAME,16)) {
|
||||
pathname.assign(ARFILE_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::ForeignSymbolTableFlag;
|
||||
if (0 == memcmp(Hdr->name, ARFILE_SVR4_SYMTAB_NAME, 16)) {
|
||||
pathname.assign(ARFILE_SVR4_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::SVR4SymbolTableFlag;
|
||||
} else {
|
||||
throw std::string("invalid foreign symbol table name");
|
||||
throw std::string("invalid SVR4 symbol table name");
|
||||
}
|
||||
} else if (isdigit(Hdr->name[1])) {
|
||||
unsigned index = atoi(&Hdr->name[1]);
|
||||
@ -152,6 +152,13 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '_':
|
||||
if (Hdr->name[1] == '_' &&
|
||||
(0 == memcmp(Hdr->name, ARFILE_BSD4_SYMTAB_NAME, 16))) {
|
||||
pathname.assign(ARFILE_BSD4_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::BSD4SymbolTableFlag;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
char* slash = (char*) memchr(Hdr->name, '/', 16);
|
||||
@ -222,9 +229,14 @@ Archive::loadArchive() {
|
||||
ArchiveMember* mbr = parseMemberHeader(At, End);
|
||||
|
||||
// check if this is the foreign symbol table
|
||||
if (mbr->isForeignSymbolTable()) {
|
||||
if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
|
||||
// We just save this but don't do anything special
|
||||
// with it. It doesn't count as the "first file".
|
||||
if (foreignST) {
|
||||
// What? Multiple foreign symbol tables? Just chuck it
|
||||
// and retain the last one found.
|
||||
delete foreignST;
|
||||
}
|
||||
foreignST = mbr;
|
||||
At += mbr->getSize();
|
||||
if ((intptr_t(At) & 1) == 1)
|
||||
@ -314,7 +326,7 @@ Archive::loadSymbolTable() {
|
||||
const char* FirstFile = At;
|
||||
ArchiveMember* mbr = parseMemberHeader(At, End);
|
||||
|
||||
if (mbr->isForeignSymbolTable()) {
|
||||
if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
|
||||
// Skip the foreign symbol table, we don't do anything with it
|
||||
At += mbr->getSize();
|
||||
if ((intptr_t(At) & 1) == 1)
|
||||
|
@ -105,8 +105,10 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
|
||||
bool writeLongName = false;
|
||||
if (mbr.isStringTable()) {
|
||||
memcpy(hdr.name,ARFILE_STRTAB_NAME,16);
|
||||
} else if (mbr.isForeignSymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_SYMTAB_NAME,16);
|
||||
} else if (mbr.isSVR4SymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_SVR4_SYMTAB_NAME,16);
|
||||
} else if (mbr.isBSD4SymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_BSD4_SYMTAB_NAME,16);
|
||||
} else if (mbr.isLLVMSymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
|
||||
} else if (TruncateNames) {
|
||||
@ -240,10 +242,11 @@ Archive::writeMember(
|
||||
// Determine if we actually should compress this member
|
||||
bool willCompress =
|
||||
(ShouldCompress &&
|
||||
!member.isForeignSymbolTable() &&
|
||||
!member.isLLVMSymbolTable() &&
|
||||
!member.isCompressed() &&
|
||||
!member.isCompressedBytecode());
|
||||
!member.isCompressedBytecode() &&
|
||||
!member.isLLVMSymbolTable() &&
|
||||
!member.isSVR4SymbolTable() &&
|
||||
!member.isBSD4SymbolTable());
|
||||
|
||||
// Perform the compression. Note that if the file is uncompressed bytecode
|
||||
// then we turn the file into compressed bytecode rather than treating it as
|
||||
@ -418,7 +421,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
// Write the file magic number
|
||||
FinalFile << ARFILE_MAGIC;
|
||||
|
||||
// If there is a foreign symbol table, put it into the file now.
|
||||
// If there is a foreign symbol table, put it into the file now. Most
|
||||
// ar(1) implementations require the symbol table to be first but llvm-ar
|
||||
// can deal with it being after a foreign symbol table. This ensures
|
||||
// compatibility with other ar(1) implementations as well as allowing the
|
||||
// archive to store both native .o and LLVM .bc files, both indexed.
|
||||
if (foreignST) {
|
||||
writeMember(*foreignST, FinalFile, false, false, false);
|
||||
}
|
||||
|
@ -65,11 +65,17 @@ void ArchiveMember::replaceWith(const sys::Path& newFile) {
|
||||
data = 0;
|
||||
path = newFile;
|
||||
|
||||
// Foreign symbol tables have an empty name
|
||||
if (path.get() == ARFILE_SYMTAB_NAME)
|
||||
flags |= ForeignSymbolTableFlag;
|
||||
// SVR4 symbol tables have an empty name
|
||||
if (path.get() == ARFILE_SVR4_SYMTAB_NAME)
|
||||
flags |= SVR4SymbolTableFlag;
|
||||
else
|
||||
flags &= ~ForeignSymbolTableFlag;
|
||||
flags &= ~SVR4SymbolTableFlag;
|
||||
|
||||
// BSD4.4 symbol tables have a special name
|
||||
if (path.get() == ARFILE_BSD4_SYMTAB_NAME)
|
||||
flags |= BSD4SymbolTableFlag;
|
||||
else
|
||||
flags &= ~BSD4SymbolTableFlag;
|
||||
|
||||
// LLVM symbol tables have a very specific name
|
||||
if (path.get() == ARFILE_LLVM_SYMTAB_NAME)
|
||||
|
@ -20,9 +20,10 @@
|
||||
|
||||
#define ARFILE_MAGIC "!<arch>\n" ///< magic string
|
||||
#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1) ///< length of magic string
|
||||
#define ARFILE_SYMTAB_NAME "/ " ///< regular symtab entry
|
||||
#define ARFILE_SVR4_SYMTAB_NAME "/ " ///< SVR4 symtab entry name
|
||||
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
|
||||
#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
|
||||
#define ARFILE_STRTAB_NAME "// " ///< Name of string table
|
||||
#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM's symtab entry
|
||||
#define ARFILE_PAD "\n" ///< inter-file align padding
|
||||
#define ARFILE_MEMBER_MAGIC "`\n" ///< fmag field magic #
|
||||
|
||||
|
@ -123,11 +123,11 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
|
||||
throw std::string("invalid string table name");
|
||||
}
|
||||
} else if (Hdr->name[1] == ' ') {
|
||||
if (0==memcmp(Hdr->name,ARFILE_SYMTAB_NAME,16)) {
|
||||
pathname.assign(ARFILE_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::ForeignSymbolTableFlag;
|
||||
if (0 == memcmp(Hdr->name, ARFILE_SVR4_SYMTAB_NAME, 16)) {
|
||||
pathname.assign(ARFILE_SVR4_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::SVR4SymbolTableFlag;
|
||||
} else {
|
||||
throw std::string("invalid foreign symbol table name");
|
||||
throw std::string("invalid SVR4 symbol table name");
|
||||
}
|
||||
} else if (isdigit(Hdr->name[1])) {
|
||||
unsigned index = atoi(&Hdr->name[1]);
|
||||
@ -152,6 +152,13 @@ Archive::parseMemberHeader(const char*& At, const char* End) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '_':
|
||||
if (Hdr->name[1] == '_' &&
|
||||
(0 == memcmp(Hdr->name, ARFILE_BSD4_SYMTAB_NAME, 16))) {
|
||||
pathname.assign(ARFILE_BSD4_SYMTAB_NAME);
|
||||
flags |= ArchiveMember::BSD4SymbolTableFlag;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
char* slash = (char*) memchr(Hdr->name, '/', 16);
|
||||
@ -222,9 +229,14 @@ Archive::loadArchive() {
|
||||
ArchiveMember* mbr = parseMemberHeader(At, End);
|
||||
|
||||
// check if this is the foreign symbol table
|
||||
if (mbr->isForeignSymbolTable()) {
|
||||
if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
|
||||
// We just save this but don't do anything special
|
||||
// with it. It doesn't count as the "first file".
|
||||
if (foreignST) {
|
||||
// What? Multiple foreign symbol tables? Just chuck it
|
||||
// and retain the last one found.
|
||||
delete foreignST;
|
||||
}
|
||||
foreignST = mbr;
|
||||
At += mbr->getSize();
|
||||
if ((intptr_t(At) & 1) == 1)
|
||||
@ -314,7 +326,7 @@ Archive::loadSymbolTable() {
|
||||
const char* FirstFile = At;
|
||||
ArchiveMember* mbr = parseMemberHeader(At, End);
|
||||
|
||||
if (mbr->isForeignSymbolTable()) {
|
||||
if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
|
||||
// Skip the foreign symbol table, we don't do anything with it
|
||||
At += mbr->getSize();
|
||||
if ((intptr_t(At) & 1) == 1)
|
||||
|
@ -105,8 +105,10 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
|
||||
bool writeLongName = false;
|
||||
if (mbr.isStringTable()) {
|
||||
memcpy(hdr.name,ARFILE_STRTAB_NAME,16);
|
||||
} else if (mbr.isForeignSymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_SYMTAB_NAME,16);
|
||||
} else if (mbr.isSVR4SymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_SVR4_SYMTAB_NAME,16);
|
||||
} else if (mbr.isBSD4SymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_BSD4_SYMTAB_NAME,16);
|
||||
} else if (mbr.isLLVMSymbolTable()) {
|
||||
memcpy(hdr.name,ARFILE_LLVM_SYMTAB_NAME,16);
|
||||
} else if (TruncateNames) {
|
||||
@ -240,10 +242,11 @@ Archive::writeMember(
|
||||
// Determine if we actually should compress this member
|
||||
bool willCompress =
|
||||
(ShouldCompress &&
|
||||
!member.isForeignSymbolTable() &&
|
||||
!member.isLLVMSymbolTable() &&
|
||||
!member.isCompressed() &&
|
||||
!member.isCompressedBytecode());
|
||||
!member.isCompressedBytecode() &&
|
||||
!member.isLLVMSymbolTable() &&
|
||||
!member.isSVR4SymbolTable() &&
|
||||
!member.isBSD4SymbolTable());
|
||||
|
||||
// Perform the compression. Note that if the file is uncompressed bytecode
|
||||
// then we turn the file into compressed bytecode rather than treating it as
|
||||
@ -418,7 +421,11 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress){
|
||||
// Write the file magic number
|
||||
FinalFile << ARFILE_MAGIC;
|
||||
|
||||
// If there is a foreign symbol table, put it into the file now.
|
||||
// If there is a foreign symbol table, put it into the file now. Most
|
||||
// ar(1) implementations require the symbol table to be first but llvm-ar
|
||||
// can deal with it being after a foreign symbol table. This ensures
|
||||
// compatibility with other ar(1) implementations as well as allowing the
|
||||
// archive to store both native .o and LLVM .bc files, both indexed.
|
||||
if (foreignST) {
|
||||
writeMember(*foreignST, FinalFile, false, false, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user