summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-09-15 21:48:40 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-09-15 21:48:40 +0000
commitf667d929ce17f686fcd667045f5943890401dda9 (patch)
tree6195d964f715f45fbca4d1bbe835124fc2b9c7b5 /llvm/lib/MC
parent44857a38fa5d04d04bca44fdfc0026ae33a014f7 (diff)
downloadbcm5719-llvm-f667d929ce17f686fcd667045f5943890401dda9.tar.gz
bcm5719-llvm-f667d929ce17f686fcd667045f5943890401dda9.zip
Add a InitSections method to the streamer interface.
The ELF implementation now creates text, data and bss to match the gnu as behavior. The text streamer still has the old MachO specific behavior since the testsuite checks that it will error when a directive is given before a setting the current section for example. A nice benefit is that -n is not required anymore when producing ELF files. llvm-svn: 114027
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp8
-rw-r--r--llvm/lib/MC/MCAssembler.cpp2
-rw-r--r--llvm/lib/MC/MCELFStreamer.cpp33
-rw-r--r--llvm/lib/MC/MCLoggingStreamer.cpp4
-rw-r--r--llvm/lib/MC/MCMachOStreamer.cpp8
-rw-r--r--llvm/lib/MC/MCNullStreamer.cpp3
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp6
-rw-r--r--llvm/lib/MC/MCParser/ELFAsmParser.cpp14
-rw-r--r--llvm/lib/MC/WinCOFFStreamer.cpp4
9 files changed, 73 insertions, 9 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 1cc8fb0b548..efde8aa3500 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -100,6 +100,14 @@ public:
virtual void SwitchSection(const MCSection *Section);
+ virtual void InitSections() {
+ // FIXME, this is MachO specific, but the testsuite
+ // expects this.
+ SwitchSection(getContext().getMachOSection("__TEXT", "__text",
+ MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
+ 0, SectionKind::getText()));
+ }
+
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 8db1536d2d5..bb1249950cb 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -739,7 +739,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
// Create dummy fragments to eliminate any empty sections, this simplifies
// layout.
if (it->getFragmentList().empty())
- new MCFillFragment(0, 1, 0, it);
+ new MCDataFragment(it);
it->setOrdinal(SectionIndex++);
}
diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp
index 6490cc7a82e..deb1a0de208 100644
--- a/llvm/lib/MC/MCELFStreamer.cpp
+++ b/llvm/lib/MC/MCELFStreamer.cpp
@@ -46,6 +46,7 @@ public:
/// @name MCStreamer Interface
/// @{
+ virtual void InitSections();
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
@@ -109,10 +110,42 @@ public:
virtual void Finish();
/// @}
+ void SetSection(StringRef Section, unsigned Type, unsigned Flags,
+ SectionKind Kind) {
+ SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
+ }
+
+ void SetSectionData() {
+ SetSection(".data", MCSectionELF::SHT_PROGBITS,
+ MCSectionELF::SHF_WRITE |MCSectionELF::SHF_ALLOC,
+ SectionKind::getDataRel());
+ EmitCodeAlignment(4, 0);
+ }
+ void SetSectionText() {
+ SetSection(".text", MCSectionELF::SHT_PROGBITS,
+ MCSectionELF::SHF_EXECINSTR |
+ MCSectionELF::SHF_ALLOC, SectionKind::getText());
+ EmitCodeAlignment(4, 0);
+ }
+ void SetSectionBss() {
+ SetSection(".bss", MCSectionELF::SHT_NOBITS,
+ MCSectionELF::SHF_WRITE |
+ MCSectionELF::SHF_ALLOC, SectionKind::getBSS());
+ EmitCodeAlignment(4, 0);
+ }
};
} // end anonymous namespace.
+void MCELFStreamer::InitSections() {
+ // This emulates the same behavior of GNU as. This makes it easier
+ // to compare the output as the major sections are in the same order.
+ SetSectionText();
+ SetSectionData();
+ SetSectionBss();
+ SetSectionText();
+}
+
void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
diff --git a/llvm/lib/MC/MCLoggingStreamer.cpp b/llvm/lib/MC/MCLoggingStreamer.cpp
index b96040abd0c..879afa44c5b 100644
--- a/llvm/lib/MC/MCLoggingStreamer.cpp
+++ b/llvm/lib/MC/MCLoggingStreamer.cpp
@@ -54,6 +54,10 @@ public:
return Child->SwitchSection(Section);
}
+ virtual void InitSections() {
+ LogCall("InitSections");
+ }
+
virtual void EmitLabel(MCSymbol *Symbol) {
LogCall("EmitLabel");
return Child->EmitLabel(Symbol);
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 671874df2c6..cd6fd50933f 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -46,6 +46,7 @@ public:
/// @name MCStreamer Interface
/// @{
+ virtual void InitSections();
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
@@ -110,6 +111,13 @@ public:
} // end anonymous namespace.
+void MCMachOStreamer::InitSections() {
+ SwitchSection(getContext().getMachOSection("__TEXT", "__text",
+ MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
+ 0, SectionKind::getText()));
+
+}
+
void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
// TODO: This is almost exactly the same as WinCOFFStreamer. Consider merging
// into MCObjectStreamer.
diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp
index f7a2f20ca4b..b2db410c111 100644
--- a/llvm/lib/MC/MCNullStreamer.cpp
+++ b/llvm/lib/MC/MCNullStreamer.cpp
@@ -25,6 +25,9 @@ namespace {
/// @name MCStreamer Interface
/// @{
+ virtual void InitSections() {
+ }
+
virtual void SwitchSection(const MCSection *Section) {
PrevSection = CurSection;
CurSection = Section;
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 5ef6f682bfa..b3ffed846d5 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -365,12 +365,8 @@ const AsmToken &AsmParser::Lex() {
bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
// Create the initial section, if requested.
- //
- // FIXME: Target hook & command line option for initial section.
if (!NoInitialTextSection)
- Out.SwitchSection(Ctx.getMachOSection("__TEXT", "__text",
- MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
- 0, SectionKind::getText()));
+ Out.InitSections();
// Prime the lexer.
Lex();
diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
index 38288d78b01..ddf988faa64 100644
--- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -51,20 +51,28 @@ public:
AddDirectiveHandler<&ELFAsmParser::ParseDirectivePrevious>(".previous");
}
+ // FIXME: Part of this logic is duplicated in the MCELFStreamer. What is
+ // the best way for us to get access to it?
bool ParseSectionDirectiveData(StringRef, SMLoc) {
- return ParseSectionSwitch(".data", MCSectionELF::SHT_PROGBITS,
+ bool ret = ParseSectionSwitch(".data", MCSectionELF::SHT_PROGBITS,
MCSectionELF::SHF_WRITE |MCSectionELF::SHF_ALLOC,
SectionKind::getDataRel());
+ getStreamer().EmitCodeAlignment(4, 0);
+ return ret;
}
bool ParseSectionDirectiveText(StringRef, SMLoc) {
- return ParseSectionSwitch(".text", MCSectionELF::SHT_PROGBITS,
+ bool ret = ParseSectionSwitch(".text", MCSectionELF::SHT_PROGBITS,
MCSectionELF::SHF_EXECINSTR |
MCSectionELF::SHF_ALLOC, SectionKind::getText());
+ getStreamer().EmitCodeAlignment(4, 0);
+ return ret;
}
bool ParseSectionDirectiveBSS(StringRef, SMLoc) {
- return ParseSectionSwitch(".bss", MCSectionELF::SHT_NOBITS,
+ bool ret = ParseSectionSwitch(".bss", MCSectionELF::SHT_NOBITS,
MCSectionELF::SHF_WRITE |
MCSectionELF::SHF_ALLOC, SectionKind::getBSS());
+ getStreamer().EmitCodeAlignment(4, 0);
+ return ret;
}
bool ParseSectionDirectiveRoData(StringRef, SMLoc) {
return ParseSectionSwitch(".rodata", MCSectionELF::SHT_PROGBITS,
diff --git a/llvm/lib/MC/WinCOFFStreamer.cpp b/llvm/lib/MC/WinCOFFStreamer.cpp
index 8a194bff215..faecfcbe333 100644
--- a/llvm/lib/MC/WinCOFFStreamer.cpp
+++ b/llvm/lib/MC/WinCOFFStreamer.cpp
@@ -48,6 +48,7 @@ public:
// MCStreamer interface
+ virtual void InitSections();
virtual void EmitLabel(MCSymbol *Symbol);
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
@@ -126,6 +127,9 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
// MCStreamer interface
+void WinCOFFStreamer::InitSections() {
+}
+
void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
// TODO: This is copied almost exactly from the MachOStreamer. Consider
// merging into MCObjectStreamer?
OpenPOWER on IntegriCloud