COFF: add support for .file symbols

Add support for emitting .file records.  This is mostly a quality of
implementation change (more complete support for COFF file emission) that was
noticed while working on COFF file emission for Windows on ARM.

A .file record is emitted as a symbol with storage class FILE (103) and the name
".file".  A series of auxiliary format 4 records follow which contain the file
name.  The filename is stored as an ANSI string and is padded with NULL if the
length is not a multiple of COFF::SymbolSize (18).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206355 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool
2014-04-16 04:15:32 +00:00
parent 30e7a0ae04
commit 73a7844c65
3 changed files with 47 additions and 2 deletions

View File

@@ -633,6 +633,35 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
// "Define" each section & symbol. This creates section & symbol
// entries in the staging area.
static_assert(sizeof(COFF::AuxiliaryFile::FileName) == COFF::SymbolSize,
"size mismatch for COFF::AuxiliaryFile::FileName");
for (auto FI = Asm.file_names_begin(), FE = Asm.file_names_end();
FI != FE; ++FI) {
// round up to calculate the number of auxiliary symbols required
unsigned Count = (FI->size() + COFF::SymbolSize) / COFF::SymbolSize;
COFFSymbol *file = createSymbol(".file");
file->Data.StorageClass = COFF::IMAGE_SYM_CLASS_FILE;
file->Aux.resize(Count);
unsigned Offset = 0;
unsigned Length = FI->size();
for (auto & Aux : file->Aux) {
Aux.AuxType = ATFile;
if (Length > COFF::SymbolSize) {
memcpy(Aux.Aux.File.FileName, FI->c_str() + Offset, COFF::SymbolSize);
Length = Length - COFF::SymbolSize;
} else {
memcpy(Aux.Aux.File.FileName, FI->c_str() + Offset, Length);
memset(&Aux.Aux.File.FileName[Length], 0, COFF::SymbolSize - Length);
Length = 0;
}
Offset = Offset + COFF::SymbolSize;
}
}
for (MCAssembler::const_iterator i = Asm.begin(), e = Asm.end(); i != e; i++)
DefineSection(*i);