diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/ELFWriter.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/MachOWriter.cpp | 21 |
2 files changed, 23 insertions, 14 deletions
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index e43346897d..4f988070fd 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -115,7 +115,9 @@ void ELFCodeEmitter::startFunction(MachineFunction &F) { // Add padding zeros to the end of the buffer to make sure that the // function will start on the correct byte alignment within the section. - OutputBuffer OB(TM, *OutBuffer); + OutputBuffer OB(*OutBuffer, + TM.getTargetData()->getPointerSizeInBits() == 64, + TM.getTargetData()->isLittleEndian()); OB.align(Align); FnStart = OutBuffer->size(); } @@ -182,7 +184,7 @@ bool ELFWriter::doInitialization(Module &M) { // Local alias to shortenify coming code. std::vector<unsigned char> &FH = FileHeader; - OutputBuffer FHOut(TM, FH); + OutputBuffer FHOut(FH, is64Bit, isLittleEndian); FHOut.outbyte(0x7F); // EI_MAG0 FHOut.outbyte('E'); // EI_MAG1 @@ -353,7 +355,7 @@ void ELFWriter::EmitSymbolTable() { StrTab.Align = 1; DataBuffer &StrTabBuf = StrTab.SectionData; - OutputBuffer StrTabOut(TM, StrTabBuf); + OutputBuffer StrTabOut(StrTabBuf, is64Bit, isLittleEndian); // Set the zero'th symbol to a null byte, as required. StrTabOut.outbyte(0); @@ -389,7 +391,7 @@ void ELFWriter::EmitSymbolTable() { SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol. SymTab.EntSize = 16; // Size of each symtab entry. FIXME: wrong for ELF64 DataBuffer &SymTabBuf = SymTab.SectionData; - OutputBuffer SymTabOut(TM, SymTabBuf); + OutputBuffer SymTabOut(SymTabBuf, is64Bit, isLittleEndian); if (!is64Bit) { // 32-bit and 64-bit formats are shuffled a bit. for (unsigned i = 0, e = SymbolTable.size(); i != e; ++i) { @@ -425,7 +427,7 @@ void ELFWriter::EmitSectionTableStringTable() { // Now that we know which section number is the .shstrtab section, update the // e_shstrndx entry in the ELF header. - OutputBuffer FHOut(TM, FileHeader); + OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian); FHOut.fixhalf(SHStrTab.SectionIdx, ELFHeader_e_shstrndx_Offset); // Set the NameIdx of each section in the string table and emit the bytes for @@ -477,7 +479,7 @@ void ELFWriter::OutputSectionsAndSectionTable() { // Now that we know where all of the sections will be emitted, set the e_shnum // entry in the ELF header. - OutputBuffer FHOut(TM, FileHeader); + OutputBuffer FHOut(FileHeader, is64Bit, isLittleEndian); FHOut.fixhalf(NumSections, ELFHeader_e_shnum_Offset); // Now that we know the offset in the file of the section table, update the @@ -491,7 +493,7 @@ void ELFWriter::OutputSectionsAndSectionTable() { DataBuffer().swap(FileHeader); DataBuffer Table; - OutputBuffer TableOut(TM, Table); + OutputBuffer TableOut(Table, is64Bit, isLittleEndian); // Emit all of the section data and build the section table itself. while (!SectionList.empty()) { diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index 29c070b371..64e11010b3 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -53,6 +53,10 @@ namespace llvm { /// Target machine description. TargetMachine &TM; + /// is64Bit/isLittleEndian - This information is inferred from the target + /// machine directly, indicating what header values and flags to set. + bool is64Bit, isLittleEndian; + /// Relocations - These are the relocations that the function needs, as /// emitted. std::vector<MachineRelocation> Relocations; @@ -75,7 +79,10 @@ namespace llvm { std::vector<intptr_t> MBBLocations; public: - MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) {} + MachOCodeEmitter(MachOWriter &mow) : MOW(mow), TM(MOW.TM) { + is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64; + isLittleEndian = TM.getTargetData()->isLittleEndian(); + } virtual void startFunction(MachineFunction &F); virtual bool finishFunction(MachineFunction &F); @@ -230,7 +237,7 @@ void MachOCodeEmitter::emitConstantPool(MachineConstantPool *MCP) { unsigned Size = TM.getTargetData()->getTypeSize(Ty); MachOWriter::MachOSection *Sec = MOW.getConstSection(Ty); - OutputBuffer SecDataOut(TM, Sec->SectionData); + OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); CPLocations.push_back(Sec->SectionData.size()); CPSections.push_back(Sec->Index); @@ -261,7 +268,7 @@ void MachOCodeEmitter::emitJumpTables(MachineJumpTableInfo *MJTI) { MachOWriter::MachOSection *Sec = MOW.getJumpTableSection(); unsigned TextSecIndex = MOW.getTextSection()->Index; - OutputBuffer SecDataOut(TM, Sec->SectionData); + OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); for (unsigned i = 0, e = JT.size(); i != e; ++i) { // For each jump table, record its offset from the start of the section, @@ -309,7 +316,7 @@ void MachOWriter::AddSymbolToSection(MachOSection *Sec, GlobalVariable *GV) { // Reserve space in the .bss section for this symbol while maintaining the // desired section alignment, which must be at least as much as required by // this symbol. - OutputBuffer SecDataOut(TM, Sec->SectionData); + OutputBuffer SecDataOut(Sec->SectionData, is64Bit, isLittleEndian); if (Align) { uint64_t OrigSize = Sec->size; @@ -451,7 +458,7 @@ void MachOWriter::EmitHeaderAndLoadCommands() { // Step #3: write the header to the file // Local alias to shortenify coming code. DataBuffer &FH = Header.HeaderData; - OutputBuffer FHOut(TM, FH); + OutputBuffer FHOut(FH, is64Bit, isLittleEndian); FHOut.outword(Header.magic); FHOut.outword(Header.cputype); @@ -638,7 +645,7 @@ void MachOWriter::BufferSymbolAndStringTable() { // Write out a leading zero byte when emitting string table, for n_strx == 0 // which means an empty string. - OutputBuffer StrTOut(TM, StrT); + OutputBuffer StrTOut(StrT, is64Bit, isLittleEndian); StrTOut.outbyte(0); // The order of the string table is: @@ -656,7 +663,7 @@ void MachOWriter::BufferSymbolAndStringTable() { } } - OutputBuffer SymTOut(TM, SymT); + OutputBuffer SymTOut(SymT, is64Bit, isLittleEndian); for (std::vector<MachOSym>::iterator I = SymbolTable.begin(), E = SymbolTable.end(); I != E; ++I) { |