aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/TargetLoweringObjectFile.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-13 00:05:07 +0000
committerChris Lattner <sabre@nondot.org>2009-08-13 00:05:07 +0000
commitc0741ebb3a2d8fa5e69796f8e47253ef4f272033 (patch)
tree51fb8b4dfb96a87218ff0b92638aff439fba7a95 /llvm/lib/Target/TargetLoweringObjectFile.cpp
parent2d5bdc2bce68585c6f91249e66adf3b71d15aa4d (diff)
downloadllvm-c0741ebb3a2d8fa5e69796f8e47253ef4f272033.zip
llvm-c0741ebb3a2d8fa5e69796f8e47253ef4f272033.tar.gz
llvm-c0741ebb3a2d8fa5e69796f8e47253ef4f272033.tar.bz2
reject invalid code like:
int x __attribute__((section("_foo, _bar"))) = 4; int y __attribute__((section("_foo, _bar, 4byte_literals"))) = 1; llvm-svn: 78867
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r--llvm/lib/Target/TargetLoweringObjectFile.cpp61
1 files changed, 34 insertions, 27 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp
index 904f01a..094e837 100644
--- a/llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -600,6 +600,16 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
= getMachOSection("__DATA","__datacoal_nt", MCSectionMachO::S_COALESCED,
SectionKind::getDataRel());
+
+ LazySymbolPointerSection
+ = getMachOSection("__DATA", "__la_symbol_ptr",
+ MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
+ SectionKind::getMetadata());
+ NonLazySymbolPointerSection
+ = getMachOSection("__DATA", "__nl_symbol_ptr",
+ MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
+ SectionKind::getMetadata());
+
if (TM.getRelocationModel() == Reloc::Static) {
StaticCtorSection
= getMachOSection("__TEXT", "__constructor", 0,SectionKind::getDataRel());
@@ -666,25 +676,6 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
SectionKind::getMetadata());
}
-/// getLazySymbolPointerSection - Return the section corresponding to
-/// the .lazy_symbol_pointer directive.
-const MCSection *TargetLoweringObjectFileMachO::
-getLazySymbolPointerSection() const {
- return getMachOSection("__DATA", "__la_symbol_ptr",
- MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
- SectionKind::getMetadata());
-}
-
-/// getNonLazySymbolPointerSection - Return the section corresponding to
-/// the .non_lazy_symbol_pointer directive.
-const MCSection *TargetLoweringObjectFileMachO::
-getNonLazySymbolPointerSection() const {
- return getMachOSection("__DATA", "__nl_symbol_ptr",
- MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
- SectionKind::getMetadata());
-}
-
-
const MCSection *TargetLoweringObjectFileMachO::
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
@@ -694,16 +685,32 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
std::string ErrorCode =
MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section,
TAA, StubSize);
- if (ErrorCode.empty())
- return getMachOSection(Segment, Section, TAA, StubSize, Kind);
+ if (!ErrorCode.empty()) {
+ // If invalid, report the error with llvm_report_error.
+ llvm_report_error("Global variable '" + GV->getNameStr() +
+ "' has an invalid section specifier '" + GV->getSection()+
+ "': " + ErrorCode + ".");
+ // Fall back to dropping it into the data section.
+ return DataSection;
+ }
+ // Get the section.
+ const MCSectionMachO *S =
+ getMachOSection(Segment, Section, TAA, StubSize, Kind);
+
+ // Okay, now that we got the section, verify that the TAA & StubSize agree.
+ // If the user declared multiple globals with different section flags, we need
+ // to reject it here.
+ if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
+ // If invalid, report the error with llvm_report_error.
+ llvm_report_error("Global variable '" + GV->getNameStr() +
+ "' section type or attributes does not match previous"
+ " section specifier");
+ }
- // If invalid, report the error with llvm_report_error.
- llvm_report_error("Global variable '" + GV->getNameStr() +
- "' has an invalid section specifier '" + GV->getSection() +
- "': " + ErrorCode + ".");
- // Fall back to dropping it into the data section.
- return DataSection;
+
+
+ return S;
}
const MCSection *TargetLoweringObjectFileMachO::