llvm.org GIT mirror llvm / e309cfa
reject invalid code like: int x __attribute__((section("_foo, _bar"))) = 4; int y __attribute__((section("_foo, _bar, 4byte_literals"))) = 1; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78867 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
3 changed file(s) with 46 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
152152 }
153153
154154 unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
155
155 unsigned getStubSize() const { return Reserved2; }
156156
157157 /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
158158 /// This is a string that can appear after a .section directive in a mach-o
240240 const MCSection *FourByteConstantSection;
241241 const MCSection *EightByteConstantSection;
242242 const MCSection *SixteenByteConstantSection;
243
244 const MCSection *LazySymbolPointerSection;
245 const MCSection *NonLazySymbolPointerSection;
243246 public:
244247 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
245248 ~TargetLoweringObjectFileMachO();
284287
285288 /// getLazySymbolPointerSection - Return the section corresponding to
286289 /// the .lazy_symbol_pointer directive.
287 const MCSection *getLazySymbolPointerSection() const;
290 const MCSection *getLazySymbolPointerSection() const {
291 return LazySymbolPointerSection;
292 }
288293
289294 /// getNonLazySymbolPointerSection - Return the section corresponding to
290295 /// the .non_lazy_symbol_pointer directive.
291 const MCSection *getNonLazySymbolPointerSection() const;
292
296 const MCSection *getNonLazySymbolPointerSection() const {
297 return NonLazySymbolPointerSection;
298 }
293299 };
294300
295301
599599 = getMachOSection("__DATA","__datacoal_nt", MCSectionMachO::S_COALESCED,
600600 SectionKind::getDataRel());
601601
602
603 LazySymbolPointerSection
604 = getMachOSection("__DATA", "__la_symbol_ptr",
605 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
606 SectionKind::getMetadata());
607 NonLazySymbolPointerSection
608 = getMachOSection("__DATA", "__nl_symbol_ptr",
609 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
610 SectionKind::getMetadata());
611
602612 if (TM.getRelocationModel() == Reloc::Static) {
603613 StaticCtorSection
604614 = getMachOSection("__TEXT", "__constructor", 0,SectionKind::getDataRel());
665675 SectionKind::getMetadata());
666676 }
667677
668 /// getLazySymbolPointerSection - Return the section corresponding to
669 /// the .lazy_symbol_pointer directive.
670 const MCSection *TargetLoweringObjectFileMachO::
671 getLazySymbolPointerSection() const {
672 return getMachOSection("__DATA", "__la_symbol_ptr",
673 MCSectionMachO::S_LAZY_SYMBOL_POINTERS,
674 SectionKind::getMetadata());
675 }
676
677 /// getNonLazySymbolPointerSection - Return the section corresponding to
678 /// the .non_lazy_symbol_pointer directive.
679 const MCSection *TargetLoweringObjectFileMachO::
680 getNonLazySymbolPointerSection() const {
681 return getMachOSection("__DATA", "__nl_symbol_ptr",
682 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
683 SectionKind::getMetadata());
684 }
685
686
687678 const MCSection *TargetLoweringObjectFileMachO::
688679 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
689680 Mangler *Mang, const TargetMachine &TM) const {
693684 std::string ErrorCode =
694685 MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section,
695686 TAA, StubSize);
696 if (ErrorCode.empty())
697 return getMachOSection(Segment, Section, TAA, StubSize, Kind);
698
699
700 // If invalid, report the error with llvm_report_error.
701 llvm_report_error("Global variable '" + GV->getNameStr() +
702 "' has an invalid section specifier '" + GV->getSection() +
703 "': " + ErrorCode + ".");
704 // Fall back to dropping it into the data section.
705 return DataSection;
687 if (!ErrorCode.empty()) {
688 // If invalid, report the error with llvm_report_error.
689 llvm_report_error("Global variable '" + GV->getNameStr() +
690 "' has an invalid section specifier '" + GV->getSection()+
691 "': " + ErrorCode + ".");
692 // Fall back to dropping it into the data section.
693 return DataSection;
694 }
695
696 // Get the section.
697 const MCSectionMachO *S =
698 getMachOSection(Segment, Section, TAA, StubSize, Kind);
699
700 // Okay, now that we got the section, verify that the TAA & StubSize agree.
701 // If the user declared multiple globals with different section flags, we need
702 // to reject it here.
703 if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
704 // If invalid, report the error with llvm_report_error.
705 llvm_report_error("Global variable '" + GV->getNameStr() +
706 "' section type or attributes does not match previous"
707 " section specifier");
708 }
709
710
711
712 return S;
706713 }
707714
708715 const MCSection *TargetLoweringObjectFileMachO::