[llvm-commits] [llvm] r78867 - in /llvm/trunk: include/llvm/MC/MCSectionMachO.h include/llvm/Target/TargetLoweringObjectFile.h lib/Target/TargetLoweringObjectFile.cpp

Chris Lattner sabre at nondot.org
Wed Aug 12 17:05:08 PDT 2009


Author: lattner
Date: Wed Aug 12 19:05:07 2009
New Revision: 78867

URL: http://llvm.org/viewvc/llvm-project?rev=78867&view=rev
Log:
reject invalid code like:
int x __attribute__((section("_foo, _bar"))) = 4;
int y __attribute__((section("_foo, _bar, 4byte_literals"))) = 1;



Modified:
    llvm/trunk/include/llvm/MC/MCSectionMachO.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp

Modified: llvm/trunk/include/llvm/MC/MCSectionMachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionMachO.h?rev=78867&r1=78866&r2=78867&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionMachO.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionMachO.h Wed Aug 12 19:05:07 2009
@@ -153,7 +153,7 @@
   }
   
   unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
-  
+  unsigned getStubSize() const { return Reserved2; }
   
   /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
   /// This is a string that can appear after a .section directive in a mach-o

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=78867&r1=78866&r2=78867&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Wed Aug 12 19:05:07 2009
@@ -241,6 +241,9 @@
   const MCSection *FourByteConstantSection;
   const MCSection *EightByteConstantSection;
   const MCSection *SixteenByteConstantSection;
+  
+  const MCSection *LazySymbolPointerSection;
+  const MCSection *NonLazySymbolPointerSection;
 public:
   TargetLoweringObjectFileMachO() : UniquingMap(0) {}
   ~TargetLoweringObjectFileMachO();
@@ -285,12 +288,15 @@
   
   /// getLazySymbolPointerSection - Return the section corresponding to
   /// the .lazy_symbol_pointer directive.
-  const MCSection *getLazySymbolPointerSection() const;
+  const MCSection *getLazySymbolPointerSection() const {
+    return LazySymbolPointerSection;
+  }
   
   /// getNonLazySymbolPointerSection - Return the section corresponding to
   /// the .non_lazy_symbol_pointer directive.
-  const MCSection *getNonLazySymbolPointerSection() const;
-  
+  const MCSection *getNonLazySymbolPointerSection() const {
+    return NonLazySymbolPointerSection;
+  }
 };
 
 

Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=78867&r1=78866&r2=78867&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Wed Aug 12 19:05:07 2009
@@ -600,6 +600,16 @@
     = 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 @@
                     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 @@
   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::





More information about the llvm-commits mailing list