mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-14 15:25:25 +00:00
Refactor getSection() method to make it easier to use.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22455 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
// This file was developed by the LLVM research group and is distributed under
|
// This file was developed by Chris Lattner and is distributed under the
|
||||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
@@ -104,10 +104,9 @@ void ELFCodeEmitter::startFunction(MachineFunction &F) {
|
|||||||
// Align the output buffer to the appropriate alignment.
|
// Align the output buffer to the appropriate alignment.
|
||||||
unsigned Align = 16; // FIXME: GENERICIZE!!
|
unsigned Align = 16; // FIXME: GENERICIZE!!
|
||||||
// Get the ELF Section that this function belongs in.
|
// Get the ELF Section that this function belongs in.
|
||||||
ES = &EW.getSection(".text");
|
ES = &EW.getSection(".text", ELFWriter::ELFSection::SHT_PROGBITS,
|
||||||
ES->Type = ELFWriter::ELFSection::SHT_PROGBITS;
|
ELFWriter::ELFSection::SHF_EXECINSTR |
|
||||||
ES->Flags = ELFWriter::ELFSection::SHF_EXECINSTR |
|
ELFWriter::ELFSection::SHF_ALLOC);
|
||||||
ELFWriter::ELFSection::SHF_ALLOC;
|
|
||||||
OutBuffer = &ES->SectionData;
|
OutBuffer = &ES->SectionData;
|
||||||
|
|
||||||
// Upgrade the section alignment if required.
|
// Upgrade the section alignment if required.
|
||||||
@@ -215,7 +214,7 @@ bool ELFWriter::doInitialization(Module &M) {
|
|||||||
outhalf(FH, 0); // e_shstrndx = Section # of '.shstrtab'
|
outhalf(FH, 0); // e_shstrndx = Section # of '.shstrtab'
|
||||||
|
|
||||||
// Add the null section, which is required to be first in the file.
|
// Add the null section, which is required to be first in the file.
|
||||||
getSection("");
|
getSection("", 0, 0);
|
||||||
|
|
||||||
// Start up the symbol table. The first entry in the symtab is the null
|
// Start up the symbol table. The first entry in the symtab is the null
|
||||||
// entry.
|
// entry.
|
||||||
@@ -316,13 +315,13 @@ bool ELFWriter::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
bool ELFWriter::doFinalization(Module &M) {
|
bool ELFWriter::doFinalization(Module &M) {
|
||||||
// Okay, the ELF header and .text sections have been completed, build the
|
// Okay, the ELF header and .text sections have been completed, build the
|
||||||
// .data, .bss, and "common" sections next.
|
// .data, .bss, and "common" sections next.
|
||||||
ELFSection &DataSection = getSection(".data");
|
ELFSection &DataSection =
|
||||||
DataSection.Type = ELFSection::SHT_PROGBITS;
|
getSection(".data", ELFSection::SHT_PROGBITS,
|
||||||
DataSection.Flags = ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC;
|
ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC);
|
||||||
|
|
||||||
ELFSection &BSSSection = getSection(".bss");
|
ELFSection &BSSSection =
|
||||||
BSSSection.Type = ELFSection::SHT_NOBITS;
|
getSection(".bss", ELFSection::SHT_NOBITS,
|
||||||
BSSSection.Flags = ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC;
|
ELFSection::SHF_WRITE | ELFSection::SHF_ALLOC);
|
||||||
|
|
||||||
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
@@ -356,8 +355,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
// FIXME: compact all local symbols to the start of the symtab.
|
// FIXME: compact all local symbols to the start of the symtab.
|
||||||
unsigned FirstNonLocalSymbol = 1;
|
unsigned FirstNonLocalSymbol = 1;
|
||||||
|
|
||||||
ELFSection &StrTab = getSection(".strtab");
|
ELFSection &StrTab = getSection(".strtab", ELFSection::SHT_STRTAB, 0);
|
||||||
StrTab.Type = ELFSection::SHT_STRTAB;
|
|
||||||
StrTab.Align = 1;
|
StrTab.Align = 1;
|
||||||
|
|
||||||
DataBuffer &StrTabBuf = StrTab.SectionData;
|
DataBuffer &StrTabBuf = StrTab.SectionData;
|
||||||
@@ -390,8 +388,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
|
|
||||||
// Now that we have emitted the string table and know the offset into the
|
// Now that we have emitted the string table and know the offset into the
|
||||||
// string table of each symbol, emit the symbol table itself.
|
// string table of each symbol, emit the symbol table itself.
|
||||||
ELFSection &SymTab = getSection(".symtab");
|
ELFSection &SymTab = getSection(".symtab", ELFSection::SHT_SYMTAB, 0);
|
||||||
SymTab.Type = ELFSection::SHT_SYMTAB;
|
|
||||||
SymTab.Align = is64Bit ? 8 : 4;
|
SymTab.Align = is64Bit ? 8 : 4;
|
||||||
SymTab.Link = SymTab.SectionIdx; // Section Index of .strtab.
|
SymTab.Link = SymTab.SectionIdx; // Section Index of .strtab.
|
||||||
SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol.
|
SymTab.Info = FirstNonLocalSymbol; // First non-STB_LOCAL symbol.
|
||||||
@@ -428,8 +425,7 @@ void ELFWriter::EmitSymbolTable() {
|
|||||||
/// section names.
|
/// section names.
|
||||||
void ELFWriter::EmitSectionTableStringTable() {
|
void ELFWriter::EmitSectionTableStringTable() {
|
||||||
// First step: add the section for the string table to the list of sections:
|
// First step: add the section for the string table to the list of sections:
|
||||||
ELFSection &SHStrTab = getSection(".shstrtab");
|
ELFSection &SHStrTab = getSection(".shstrtab", ELFSection::SHT_STRTAB, 0);
|
||||||
SHStrTab.Type = ELFSection::SHT_STRTAB;
|
|
||||||
|
|
||||||
// Now that we know which section number is the .shstrtab section, update the
|
// Now that we know which section number is the .shstrtab section, update the
|
||||||
// e_shstrndx entry in the ELF header.
|
// e_shstrndx entry in the ELF header.
|
||||||
|
Reference in New Issue
Block a user