llvm.org GIT mirror llvm / b808588
Change MCSectionELF to represent a section semantically instead of syntactically as a string, very similiar to what Chris did with MachO. The parsing support and validation is not introduced yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78890 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 10 years ago
11 changed file(s) with 516 addition(s) and 201 deletion(s). Raw diff Collapse all Expand all
4040 raw_ostream &OS) const = 0;
4141 };
4242
43
44 class MCSectionELF : public MCSection {
45 std::string Name;
46
47 /// IsDirective - This is true if the section name is a directive, not
48 /// something that should be printed with ".section".
49 ///
50 /// FIXME: This is a hack. Switch to a semantic view of the section instead
51 /// of a syntactic one.
52 bool IsDirective;
53
54 MCSectionELF(const StringRef &name, bool isDirective, SectionKind K)
55 : MCSection(K), Name(name), IsDirective(isDirective) {
56 }
57 public:
58
59 static MCSectionELF *Create(const StringRef &Name, bool IsDirective,
60 SectionKind K, MCContext &Ctx);
61
62 const std::string &getName() const { return Name; }
63 bool isDirective() const { return IsDirective; }
64
65
66 virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
67 raw_ostream &OS) const;
68 };
69
7043 class MCSectionCOFF : public MCSection {
7144 std::string Name;
7245
0 //===- MCSectionELF.h - ELF Machine Code Sections ---------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the MCSectionELF class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_MC_MCSECTIONELF_H
14 #define LLVM_MC_MCSECTIONELF_H
15
16 #include "llvm/MC/MCSection.h"
17
18 namespace llvm {
19
20 /// MCSectionELF - This represents a section on linux, lots of unix variants
21 /// and some bare metal systems.
22 class MCSectionELF : public MCSection {
23 std::string SectionName;
24
25 /// Type - This is the sh_type field of a section, drawn from the enums below.
26 unsigned Type;
27
28 /// Flags - This is the sh_flags field of a section, drawn from the enums.
29 /// below.
30 unsigned Flags;
31
32 /// HasCrazyBSS - PPC/Linux doesn't support the .bss directive, it
33 /// needs .section .bss. TODO: replace this with a TAI method.
34 bool HasCrazyBSS;
35
36 /// IsExplicit - Indicates that this section comes from globals with an
37 /// explicit section specfied.
38 bool IsExplicit;
39
40 MCSectionELF(const StringRef &Section, unsigned T, unsigned F,
41 SectionKind K, bool hasCrazyBSS, bool isExplicit)
42 : MCSection(K), SectionName(Section.str()), Type(T), Flags(F),
43 HasCrazyBSS(hasCrazyBSS), IsExplicit(isExplicit) {}
44 public:
45
46 static MCSectionELF *Create(const StringRef &Section, unsigned Type,
47 unsigned Flags, SectionKind K,
48 bool hasCrazyBSS, bool isExplicit,
49 MCContext &Ctx);
50
51 /// ShouldOmitSectionDirective - Decides whether a '.section' directive
52 /// should be printed before the section name
53 bool ShouldOmitSectionDirective(const char *Name) const;
54
55 /// ShouldPrintSectionType - Only prints the section type if supported
56 bool ShouldPrintSectionType(unsigned Ty) const;
57
58 /// These are the section type and flags fields. An ELF section can have
59 /// only one Type, but can have more than one of the flags specified.
60 ///
61 /// Valid section types.
62 enum {
63 // This value marks the section header as inactive.
64 SHT_NULL = 0x00U,
65
66 // Holds information defined by the program, with custom format and meaning.
67 SHT_PROGBITS = 0x01U,
68
69 // This section holds a symbol table.
70 SHT_SYMTAB = 0x02U,
71
72 // The section holds a string table.
73 SHT_STRTAB = 0x03U,
74
75 // The section holds relocation entries with explicit addends.
76 SHT_RELA = 0x04U,
77
78 // The section holds a symbol hash table.
79 SHT_HASH = 0x05U,
80
81 // Information for dynamic linking.
82 SHT_DYNAMIC = 0x06U,
83
84 // The section holds information that marks the file in some way.
85 SHT_NOTE = 0x07U,
86
87 // A section of this type occupies no space in the file.
88 SHT_NOBITS = 0x08U,
89
90 // The section holds relocation entries without explicit addends.
91 SHT_REL = 0x09U,
92
93 // This section type is reserved but has unspecified semantics.
94 SHT_SHLIB = 0x0aU,
95
96 // This section holds a symbol table.
97 SHT_DYNSYM = 0x0bU,
98
99 // This section contains an array of pointers to initialization functions.
100 SHT_INIT_ARRAY = 0x0eU,
101
102 // This section contains an array of pointers to termination functions.
103 SHT_FINI_ARRAY = 0x0fU,
104
105 // This section contains an array of pointers to functions that are invoked
106 // before all other initialization functions.
107 SHT_PREINIT_ARRAY = 0x10U,
108
109 // A section group is a set of sections that are related and that must be
110 // treated specially by the linker.
111 SHT_GROUP = 0x11U,
112
113 // This section is associated with a section of type SHT_SYMTAB, when the
114 // referenced symbol table contain the escape value SHN_XINDEX
115 SHT_SYMTAB_SHNDX = 0x12U,
116
117 LAST_KNOWN_SECTION_TYPE = SHT_SYMTAB_SHNDX
118 };
119
120 /// Valid section flags.
121 enum {
122 // The section contains data that should be writable.
123 SHF_WRITE = 0x1U,
124
125 // The section occupies memory during execution.
126 SHF_ALLOC = 0x2U,
127
128 // The section contains executable machine instructions.
129 SHF_EXECINSTR = 0x4U,
130
131 // The data in the section may be merged to eliminate duplication.
132 SHF_MERGE = 0x10U,
133
134 // Elements in the section consist of null-terminated character strings.
135 SHF_STRINGS = 0x20U,
136
137 // A field in this section holds a section header table index.
138 SHF_INFO_LINK = 0x40U,
139
140 // Adds special ordering requirements for link editors.
141 SHF_LINK_ORDER = 0x80U,
142
143 // This section requires special OS-specific processing to avoid incorrect
144 // behavior.
145 SHF_OS_NONCONFORMING = 0x100U,
146
147 // This section is a member of a section group.
148 SHF_GROUP = 0x200U,
149
150 // This section holds Thread-Local Storage.
151 SHF_TLS = 0x400U
152 };
153
154 StringRef getSectionName() const {
155 return StringRef(SectionName);
156 }
157
158 unsigned getType() const { return Type; }
159 unsigned getFlags() const { return Flags; }
160
161 virtual void PrintSwitchToSection(const TargetAsmInfo &TAI,
162 raw_ostream &OS) const;
163 };
164
165 } // end namespace llvm
166
167 #endif
203203 const MCSection *MergeableConst16Section;
204204
205205 protected:
206 const MCSection *getELFSection(const char *Name, bool isDirective,
207 SectionKind Kind) const;
206 const MCSection *getELFSection(StringRef Section, unsigned Type,
207 unsigned Flags, SectionKind Kind,
208 bool IsExplicit = false) const;
208209 public:
209210 TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
210211 bool hasCrazyBSS = false)
4242 #include "llvm/CodeGen/MachineCodeEmitter.h"
4343 #include "llvm/CodeGen/MachineConstantPool.h"
4444 #include "llvm/MC/MCContext.h"
45 #include "llvm/MC/MCSection.h"
45 #include "llvm/MC/MCSectionELF.h"
4646 #include "llvm/Target/TargetAsmInfo.h"
4747 #include "llvm/Target/TargetData.h"
4848 #include "llvm/Target/TargetELFWriterInfo.h"
177177
178178 // getCtorSection - Get the static constructor section
179179 ELFSection &ELFWriter::getCtorSection() {
180 const MCSection *Ctor = TLOF.getStaticCtorSection();
181 return getSection(((MCSectionELF*)Ctor)->getName(), ELFSection::SHT_PROGBITS,
180 const MCSectionELF *Ctor = (const MCSectionELF *)TLOF.getStaticCtorSection();
181 return getSection(Ctor->getSectionName(), ELFSection::SHT_PROGBITS,
182182 getElfSectionFlags(Ctor->getKind()));
183183 }
184184
185185 // getDtorSection - Get the static destructor section
186186 ELFSection &ELFWriter::getDtorSection() {
187 const MCSection *Dtor = TLOF.getStaticDtorSection();
188 return getSection(((MCSectionELF*)Dtor)->getName(), ELFSection::SHT_PROGBITS,
187 const MCSectionELF *Dtor = (const MCSectionELF *)TLOF.getStaticDtorSection();
188 return getSection(Dtor->getSectionName(), ELFSection::SHT_PROGBITS,
189189 getElfSectionFlags(Dtor->getKind()));
190190 }
191191
192192 // getTextSection - Get the text section for the specified function
193193 ELFSection &ELFWriter::getTextSection(Function *F) {
194 const MCSection *Text = TLOF.SectionForGlobal(F, Mang, TM);
195 return getSection(((MCSectionELF*)Text)->getName(), ELFSection::SHT_PROGBITS,
194 const MCSectionELF *Text =
195 (const MCSectionELF *)TLOF.SectionForGlobal(F, Mang, TM);
196 return getSection(Text->getSectionName(), ELFSection::SHT_PROGBITS,
196197 getElfSectionFlags(Text->getKind()));
197198 }
198199
199200 // getJumpTableSection - Get a read only section for constants when
200201 // emitting jump tables. TODO: add PIC support
201202 ELFSection &ELFWriter::getJumpTableSection() {
202 const MCSection *JT = TLOF.getSectionForConstant(SectionKind::getReadOnly());
203 return getSection(((MCSectionELF*)JT)->getName(),
203 const MCSectionELF *JT =
204 (const MCSectionELF *)TLOF.getSectionForConstant(SectionKind::getReadOnly());
205 return getSection(JT->getSectionName(),
204206 ELFSection::SHT_PROGBITS,
205207 getElfSectionFlags(JT->getKind()),
206208 TM.getTargetData()->getPointerABIAlignment());
225227 }
226228 }
227229
228 const MCSection *CPSect = TLOF.getSectionForConstant(Kind);
229 return getSection(((MCSectionELF*)CPSect)->getName(),
230 const MCSectionELF *CPSect =
231 (const MCSectionELF *)TLOF.getSectionForConstant(Kind);
232 return getSection(CPSect->getSectionName(),
230233 ELFSection::SHT_PROGBITS,
231234 getElfSectionFlags(Kind),
232235 CPE.getAlignment());
357360 return;
358361
359362 // Get the ELF section where this global belongs from TLOF
360 const MCSection *S = TLOF.SectionForGlobal(GV, Mang, TM);
361 SectionKind Kind = ((MCSectionELF*)S)->getKind();
363 const MCSectionELF *S =
364 (const MCSectionELF *)TLOF.SectionForGlobal(GV, Mang, TM);
365 SectionKind Kind = S->getKind();
362366 unsigned SectionFlags = getElfSectionFlags(Kind);
363367
364368 // The symbol align should update the section alignment if needed
369373
370374 if (isELFCommonSym(GVar)) {
371375 GblSym->SectionIdx = ELFSection::SHN_COMMON;
372 getSection(((MCSectionELF*)S)->getName(),
376 getSection(S->getSectionName(),
373377 ELFSection::SHT_NOBITS, SectionFlags, 1);
374378
375379 // A new linkonce section is created for each global in the
379383
380384 } else if (isELFBssSym(GVar, Kind)) {
381385 ELFSection &ES =
382 getSection(((MCSectionELF*)S)->getName(), ELFSection::SHT_NOBITS,
386 getSection(S->getSectionName(), ELFSection::SHT_NOBITS,
383387 SectionFlags);
384388 GblSym->SectionIdx = ES.SectionIdx;
385389
395399
396400 } else { // The symbol must go to some kind of data section
397401 ELFSection &ES =
398 getSection(((MCSectionELF*)S)->getName(), ELFSection::SHT_PROGBITS,
402 getSection(S->getSectionName(), ELFSection::SHT_PROGBITS,
399403 SectionFlags);
400404 GblSym->SectionIdx = ES.SectionIdx;
401405
33 MCAsmStreamer.cpp
44 MCContext.cpp
55 MCSection.cpp
6 MCSectionELF.cpp
67 MCSectionMachO.cpp
78 MCStreamer.cpp
89 TargetAsmParser.cpp
1818
1919 MCSection::~MCSection() {
2020 }
21
22
23 //===----------------------------------------------------------------------===//
24 // MCSectionELF
25 //===----------------------------------------------------------------------===//
26
27 MCSectionELF *MCSectionELF::
28 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
29 return new (Ctx) MCSectionELF(Name, IsDirective, K);
30 }
31
32 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
33 raw_ostream &OS) const {
34 if (isDirective()) {
35 OS << getName() << '\n';
36 return;
37 }
38
39 OS << "\t.section\t" << getName();
40
41 // Handle the weird solaris syntax if desired.
42 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
43 !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
44 if (!getKind().isMetadata())
45 OS << ",#alloc";
46 if (getKind().isText())
47 OS << ",#execinstr";
48 if (getKind().isWriteable())
49 OS << ",#write";
50 if (getKind().isThreadLocal())
51 OS << ",#tls";
52 } else {
53 OS << ",\"";
54
55 if (!getKind().isMetadata())
56 OS << 'a';
57 if (getKind().isText())
58 OS << 'x';
59 if (getKind().isWriteable())
60 OS << 'w';
61 if (getKind().isMergeable1ByteCString() ||
62 getKind().isMergeable2ByteCString() ||
63 getKind().isMergeable4ByteCString() ||
64 getKind().isMergeableConst4() ||
65 getKind().isMergeableConst8() ||
66 getKind().isMergeableConst16())
67 OS << 'M';
68 if (getKind().isMergeable1ByteCString() ||
69 getKind().isMergeable2ByteCString() ||
70 getKind().isMergeable4ByteCString())
71 OS << 'S';
72 if (getKind().isThreadLocal())
73 OS << 'T';
74
75 OS << "\",";
76
77 // If comment string is '@', e.g. as on ARM - use '%' instead
78 if (TAI.getCommentString()[0] == '@')
79 OS << '%';
80 else
81 OS << '@';
82
83 if (getKind().isBSS() || getKind().isThreadBSS())
84 OS << "nobits";
85 else
86 OS << "progbits";
87
88 if (getKind().isMergeable1ByteCString()) {
89 OS << ",1";
90 } else if (getKind().isMergeable2ByteCString()) {
91 OS << ",2";
92 } else if (getKind().isMergeable4ByteCString()) {
93 OS << ",4";
94 } else if (getKind().isMergeableConst4()) {
95 OS << ",4";
96 } else if (getKind().isMergeableConst8()) {
97 OS << ",8";
98 } else if (getKind().isMergeableConst16()) {
99 OS << ",16";
100 }
101 }
102
103 OS << '\n';
104 }
105
10621
10722 //===----------------------------------------------------------------------===//
10823 // MCSectionCOFF
0 //===- lib/MC/MCSectionELF.cpp - ELF Code Section Representation ----------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/MC/MCSectionELF.h"
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include "llvm/Target/TargetAsmInfo.h"
13
14 using namespace llvm;
15
16 MCSectionELF *MCSectionELF::
17 Create(const StringRef &Section, unsigned Type, unsigned Flags,
18 SectionKind K, bool hasCrazyBSS, bool isExplicit, MCContext &Ctx) {
19 return new
20 (Ctx) MCSectionELF(Section, Type, Flags, K, hasCrazyBSS, isExplicit);
21 }
22
23 // ShouldOmitSectionDirective - Decides whether a '.section' directive
24 // should be printed before the section name
25 bool MCSectionELF::ShouldOmitSectionDirective(const char *Name) const {
26
27 // PPC/Linux doesn't support the .bss directive, it needs .section .bss.
28 // FIXME: Does .section .bss/.data/.text work everywhere??
29 if ((!HasCrazyBSS && strncmp(Name, ".bss", 4) == 0) ||
30 strncmp(Name, ".text", 5) == 0 ||
31 strncmp(Name, ".data", 5) == 0)
32 return true;
33
34 return false;
35 }
36
37 // ShouldPrintSectionType - Only prints the section type if supported
38 bool MCSectionELF::ShouldPrintSectionType(unsigned Ty) const {
39
40 if (IsExplicit && !(Ty == SHT_NOBITS || Ty == SHT_PROGBITS))
41 return false;
42
43 return true;
44 }
45
46 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
47 raw_ostream &OS) const {
48
49 if (ShouldOmitSectionDirective(SectionName.c_str())) {
50 OS << '\t' << getSectionName() << '\n';
51 return;
52 }
53
54 OS << "\t.section\t" << getSectionName();
55
56 // Handle the weird solaris syntax if desired.
57 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
58 !(Flags & MCSectionELF::SHF_MERGE)) {
59 if (Flags & MCSectionELF::SHF_ALLOC)
60 OS << ",#alloc";
61 if (Flags & MCSectionELF::SHF_EXECINSTR)
62 OS << ",#execinstr";
63 if (Flags & MCSectionELF::SHF_WRITE)
64 OS << ",#write";
65 if (Flags & MCSectionELF::SHF_TLS)
66 OS << ",#tls";
67 } else {
68 OS << ",\"";
69
70 if (Flags & MCSectionELF::SHF_ALLOC)
71 OS << 'a';
72 if (Flags & MCSectionELF::SHF_EXECINSTR)
73 OS << 'x';
74 if (Flags & MCSectionELF::SHF_WRITE)
75 OS << 'w';
76 if (Flags & MCSectionELF::SHF_MERGE)
77 OS << 'M';
78 if (Flags & MCSectionELF::SHF_STRINGS)
79 OS << 'S';
80 if (Flags & MCSectionELF::SHF_TLS)
81 OS << 'T';
82
83 OS << '"';
84
85 if (ShouldPrintSectionType(Type)) {
86 OS << ',';
87
88 // If comment string is '@', e.g. as on ARM - use '%' instead
89 if (TAI.getCommentString()[0] == '@')
90 OS << '%';
91 else
92 OS << '@';
93
94 if (Type == MCSectionELF::SHT_INIT_ARRAY)
95 OS << "init_array";
96 else if (Type == MCSectionELF::SHT_FINI_ARRAY)
97 OS << "fini_array";
98 else if (Type == MCSectionELF::SHT_PREINIT_ARRAY)
99 OS << "preinit_array";
100 else if (Type == MCSectionELF::SHT_NOBITS)
101 OS << "nobits";
102 else if (Type == MCSectionELF::SHT_PROGBITS)
103 OS << "progbits";
104
105 if (getKind().isMergeable1ByteCString()) {
106 OS << ",1";
107 } else if (getKind().isMergeable2ByteCString()) {
108 OS << ",2";
109 } else if (getKind().isMergeable4ByteCString() ||
110 getKind().isMergeableConst4()) {
111 OS << ",4";
112 } else if (getKind().isMergeableConst8()) {
113 OS << ",8";
114 } else if (getKind().isMergeableConst16()) {
115 OS << ",16";
116 }
117 }
118 }
119
120 OS << '\n';
121 }
122
1010 #define LLVM_TARGET_ARM_TARGETOBJECTFILE_H
1111
1212 #include "llvm/Target/TargetLoweringObjectFile.h"
13 #include "llvm/MC/MCSectionELF.h"
1314
1415 namespace llvm {
1516
2021 void Initialize(MCContext &Ctx, const TargetMachine &TM) {
2122 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
2223
23 // FIXME: Add new attribute/flag to MCSection for init_array/fini_array.
24 // That will allow not treating these as "directives".
2524 if (TM.getSubtarget().isAAPCS_ABI()) {
2625 StaticCtorSection =
27 getELFSection("\t.section .init_array,\"aw\",%init_array", true,
26 getELFSection(".init_array", MCSectionELF::SHT_INIT_ARRAY,
27 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
2828 SectionKind::getDataRel());
2929 StaticDtorSection =
30 getELFSection("\t.section .fini_array,\"aw\",%fini_array", true,
30 getELFSection(".fini_array", MCSectionELF::SHT_FINI_ARRAY,
31 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
3132 SectionKind::getDataRel());
3233 }
3334 }
1818 #include "llvm/GlobalVariable.h"
1919 #include "llvm/MC/MCContext.h"
2020 #include "llvm/MC/MCSectionMachO.h"
21 #include "llvm/Target/TargetAsmInfo.h"
21 #include "llvm/MC/MCSectionELF.h"
2222 #include "llvm/Target/TargetData.h"
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/Target/TargetOptions.h"
287287 }
288288
289289 const MCSection *TargetLoweringObjectFileELF::
290 getELFSection(const char *Name, bool isDirective, SectionKind Kind) const {
291 // Create the map if it doesn't already exist.
290 getELFSection(StringRef Section, unsigned Type, unsigned Flags,
291 SectionKind Kind, bool IsExplicit) const {
292292 if (UniquingMap == 0)
293293 UniquingMap = new ELFUniqueMapTy();
294294 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
295295
296296 // Do the lookup, if we have a hit, return it.
297 const MCSectionELF *&Entry = Map[Name];
297 const MCSectionELF *&Entry = Map[Section];
298298 if (Entry) return Entry;
299299
300 return Entry = MCSectionELF::Create(Name, isDirective, Kind, getContext());
300 return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, HasCrazyBSS,
301 IsExplicit, getContext());
301302 }
302303
303304 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
304305 const TargetMachine &TM) {
305306 TargetLoweringObjectFile::Initialize(Ctx, TM);
306 if (!HasCrazyBSS)
307 BSSSection = getELFSection("\t.bss", true, SectionKind::getBSS());
308 else
309 // PPC/Linux doesn't support the .bss directive, it needs .section .bss.
310 // FIXME: Does .section .bss work everywhere??
311 // FIXME2: this should just be handle by the section printer. We should get
312 // away from syntactic view of the sections and MCSection should just be a
313 // semantic view.
314 BSSSection = getELFSection("\t.bss", false, SectionKind::getBSS());
315
307
308 BSSSection =
309 getELFSection(".bss", MCSectionELF::SHT_NOBITS,
310 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
311 SectionKind::getBSS());
316312
317 TextSection = getELFSection("\t.text", true, SectionKind::getText());
318 DataSection = getELFSection("\t.data", true, SectionKind::getDataRel());
319 ReadOnlySection =
320 getELFSection("\t.rodata", false, SectionKind::getReadOnly());
321 TLSDataSection =
322 getELFSection("\t.tdata", false, SectionKind::getThreadData());
323
324 TLSBSSSection = getELFSection("\t.tbss", false,
325 SectionKind::getThreadBSS());
326
327 DataRelSection = getELFSection("\t.data.rel", false,
328 SectionKind::getDataRel());
329 DataRelLocalSection = getELFSection("\t.data.rel.local", false,
330 SectionKind::getDataRelLocal());
331 DataRelROSection = getELFSection("\t.data.rel.ro", false,
332 SectionKind::getReadOnlyWithRel());
333 DataRelROLocalSection =
334 getELFSection("\t.data.rel.ro.local", false,
335 SectionKind::getReadOnlyWithRelLocal());
313 TextSection =
314 getELFSection(".text", MCSectionELF::SHT_PROGBITS,
315 MCSectionELF::SHF_EXECINSTR | MCSectionELF::SHF_ALLOC,
316 SectionKind::getText());
317
318 DataSection =
319 getELFSection(".data", MCSectionELF::SHT_PROGBITS,
320 MCSectionELF::SHF_WRITE | MCSectionELF::SHF_ALLOC,
321 SectionKind::getDataRel());
322
323 ReadOnlySection =
324 getELFSection(".rodata", MCSectionELF::SHT_PROGBITS,
325 MCSectionELF::SHF_ALLOC,
326 SectionKind::getReadOnly());
327
328 TLSDataSection =
329 getELFSection(".tdata", MCSectionELF::SHT_PROGBITS,
330 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_TLS |
331 MCSectionELF::SHF_WRITE, SectionKind::getThreadData());
332
333 TLSBSSSection =
334 getELFSection(".tbss", MCSectionELF::SHT_NOBITS,
335 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_TLS |
336 MCSectionELF::SHF_WRITE, SectionKind::getThreadBSS());
337
338 DataRelSection =
339 getELFSection(".data.rel", MCSectionELF::SHT_PROGBITS,
340 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
341 SectionKind::getDataRel());
342
343 DataRelLocalSection =
344 getELFSection(".data.rel.local", MCSectionELF::SHT_PROGBITS,
345 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
346 SectionKind::getDataRelLocal());
347
348 DataRelROSection =
349 getELFSection(".data.rel.ro", MCSectionELF::SHT_PROGBITS,
350 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
351 SectionKind::getReadOnlyWithRel());
352
353 DataRelROLocalSection =
354 getELFSection(".data.rel.ro.local", MCSectionELF::SHT_PROGBITS,
355 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
356 SectionKind::getReadOnlyWithRelLocal());
336357
337 MergeableConst4Section = getELFSection(".rodata.cst4", false,
338 SectionKind::getMergeableConst4());
339 MergeableConst8Section = getELFSection(".rodata.cst8", false,
340 SectionKind::getMergeableConst8());
341 MergeableConst16Section = getELFSection(".rodata.cst16", false,
342 SectionKind::getMergeableConst16());
358 MergeableConst4Section =
359 getELFSection(".rodata.cst4", MCSectionELF::SHT_PROGBITS,
360 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE,
361 SectionKind::getMergeableConst4());
362
363 MergeableConst8Section =
364 getELFSection(".rodata.cst8", MCSectionELF::SHT_PROGBITS,
365 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE,
366 SectionKind::getMergeableConst8());
367
368 MergeableConst16Section =
369 getELFSection(".rodata.cst16", MCSectionELF::SHT_PROGBITS,
370 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_MERGE,
371 SectionKind::getMergeableConst16());
343372
344373 StaticCtorSection =
345 getELFSection(".ctors", false, SectionKind::getDataRel());
374 getELFSection(".ctors", MCSectionELF::SHT_PROGBITS,
375 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
376 SectionKind::getDataRel());
377
346378 StaticDtorSection =
347 getELFSection(".dtors", false, SectionKind::getDataRel());
379 getELFSection(".dtors", MCSectionELF::SHT_PROGBITS,
380 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
381 SectionKind::getDataRel());
348382
349383 // Exception Handling Sections.
350384
353387 // runtime hit for C++ apps. Either the contents of the LSDA need to be
354388 // adjusted or this should be a data section.
355389 LSDASection =
356 getELFSection(".gcc_except_table", false, SectionKind::getReadOnly());
390 getELFSection(".gcc_except_table", MCSectionELF::SHT_PROGBITS,
391 MCSectionELF::SHF_ALLOC, SectionKind::getReadOnly());
357392 EHFrameSection =
358 getELFSection(".eh_frame", false, SectionKind::getDataRel());
393 getELFSection(".eh_frame", MCSectionELF::SHT_PROGBITS,
394 MCSectionELF::SHF_ALLOC, SectionKind::getDataRel());
359395
360396 // Debug Info Sections.
361397 DwarfAbbrevSection =
362 getELFSection(".debug_abbrev", false, SectionKind::getMetadata());
398 getELFSection(".debug_abbrev", MCSectionELF::SHT_PROGBITS, 0,
399 SectionKind::getMetadata());
363400 DwarfInfoSection =
364 getELFSection(".debug_info", false, SectionKind::getMetadata());
401 getELFSection(".debug_info", MCSectionELF::SHT_PROGBITS, 0,
402 SectionKind::getMetadata());
365403 DwarfLineSection =
366 getELFSection(".debug_line", false, SectionKind::getMetadata());
404 getELFSection(".debug_line", MCSectionELF::SHT_PROGBITS, 0,
405 SectionKind::getMetadata());
367406 DwarfFrameSection =
368 getELFSection(".debug_frame", false, SectionKind::getMetadata());
407 getELFSection(".debug_frame", MCSectionELF::SHT_PROGBITS, 0,
408 SectionKind::getMetadata());
369409 DwarfPubNamesSection =
370 getELFSection(".debug_pubnames", false, SectionKind::getMetadata());
410 getELFSection(".debug_pubnames", MCSectionELF::SHT_PROGBITS, 0,
411 SectionKind::getMetadata());
371412 DwarfPubTypesSection =
372 getELFSection(".debug_pubtypes", false, SectionKind::getMetadata());
413 getELFSection(".debug_pubtypes", MCSectionELF::SHT_PROGBITS, 0,
414 SectionKind::getMetadata());
373415 DwarfStrSection =
374 getELFSection(".debug_str", false, SectionKind::getMetadata());
416 getELFSection(".debug_str", MCSectionELF::SHT_PROGBITS, 0,
417 SectionKind::getMetadata());
375418 DwarfLocSection =
376 getELFSection(".debug_loc", false, SectionKind::getMetadata());
419 getELFSection(".debug_loc", MCSectionELF::SHT_PROGBITS, 0,
420 SectionKind::getMetadata());
377421 DwarfARangesSection =
378 getELFSection(".debug_aranges", false, SectionKind::getMetadata());
422 getELFSection(".debug_aranges", MCSectionELF::SHT_PROGBITS, 0,
423 SectionKind::getMetadata());
379424 DwarfRangesSection =
380 getELFSection(".debug_ranges", false, SectionKind::getMetadata());
425 getELFSection(".debug_ranges", MCSectionELF::SHT_PROGBITS, 0,
426 SectionKind::getMetadata());
381427 DwarfMacroInfoSection =
382 getELFSection(".debug_macinfo", false, SectionKind::getMetadata());
428 getELFSection(".debug_macinfo", MCSectionELF::SHT_PROGBITS, 0,
429 SectionKind::getMetadata());
383430 }
384431
385432
409456 return K;
410457 }
411458
459
460 static unsigned
461 getELFSectionType(const char *Name, SectionKind K) {
462
463 if (strncmp(Name, ".init_array", 11) == 0)
464 return MCSectionELF::SHT_INIT_ARRAY;
465
466 if (strncmp(Name, ".fini_array", 11) == 0)
467 return MCSectionELF::SHT_FINI_ARRAY;
468
469 if (strncmp(Name, ".preinit_array", 14) == 0)
470 return MCSectionELF::SHT_PREINIT_ARRAY;
471
472 if (K.isBSS() || K.isThreadBSS())
473 return MCSectionELF::SHT_NOBITS;
474
475 return MCSectionELF::SHT_PROGBITS;
476 }
477
478
479 static unsigned
480 getELFSectionFlags(SectionKind K) {
481 unsigned Flags = 0;
482
483 if (!K.isMetadata())
484 Flags |= MCSectionELF::SHF_ALLOC;
485
486 if (K.isWriteable())
487 Flags |= MCSectionELF::SHF_WRITE;
488
489 if (K.isThreadLocal())
490 Flags |= MCSectionELF::SHF_TLS;
491
492 // K.isMergeableConst() is left out to honour PR4650
493 if (K.isMergeableCString() || K.isMergeableConst4() ||
494 K.isMergeableConst8() || K.isMergeableConst16())
495 Flags |= MCSectionELF::SHF_MERGE;
496
497 if (K.isMergeableCString())
498 Flags |= MCSectionELF::SHF_STRINGS;
499
500 return Flags;
501 }
502
503
412504 const MCSection *TargetLoweringObjectFileELF::
413505 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
414506 Mangler *Mang, const TargetMachine &TM) const {
507 const char *SectionName = GV->getSection().c_str();
508
415509 // Infer section flags from the section name if we can.
416 Kind = getELFKindForNamedSection(GV->getSection().c_str(), Kind);
417
418 return getELFSection(GV->getSection().c_str(), false, Kind);
510 Kind = getELFKindForNamedSection(SectionName, Kind);
511
512 return getELFSection(SectionName,
513 getELFSectionType(SectionName, Kind),
514 getELFSectionFlags(Kind), Kind, true);
419515 }
420516
421517 static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
444540 if (GV->isWeakForLinker()) {
445541 const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
446542 std::string Name = Mang->makeNameProper(GV->getNameStr());
447 return getELFSection((Prefix+Name).c_str(), false, Kind);
543
544 return getELFSection((Prefix+Name).c_str(),
545 getELFSectionType((Prefix+Name).c_str(), Kind),
546 getELFSectionFlags(Kind),
547 Kind);
448548 }
449549
450550 if (Kind.isText()) return TextSection;
469569
470570
471571 std::string Name = SizeSpec + utostr(Align);
472 return getELFSection(Name.c_str(), false, Kind);
572 return getELFSection(Name.c_str(), MCSectionELF::SHT_PROGBITS,
573 MCSectionELF::SHF_ALLOC |
574 MCSectionELF::SHF_MERGE |
575 MCSectionELF::SHF_STRINGS,
576 Kind);
473577 }
474578
475579 if (Kind.isMergeableConst()) {
88
99 #include "XCoreTargetObjectFile.h"
1010 #include "XCoreSubtarget.h"
11 #include "llvm/MC/MCSectionELF.h"
1112 #include "llvm/Target/TargetMachine.h"
1213 using namespace llvm;
1314
1516 void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
1617 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
1718
18 TextSection = getELFSection("\t.text", true, SectionKind::getText());
19 DataSection = getELFSection("\t.dp.data", false, SectionKind::getDataRel());
20 BSSSection = getELFSection("\t.dp.bss", false, SectionKind::getBSS());
19 DataSection = getELFSection(".dp.data", MCSectionELF::SHT_PROGBITS,
20 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
21 SectionKind::getDataRel());
22 BSSSection = getELFSection(".dp.bss", MCSectionELF::SHT_NOBITS,
23 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
24 SectionKind::getBSS());
2125
2226 // TLS globals are lowered in the backend to arrays indexed by the current
2327 // thread id. After lowering they require no special handling by the linker
2731
2832 if (TM.getSubtarget().isXS1A())
2933 // FIXME: Why is this writable ("datarel")???
30 ReadOnlySection = getELFSection("\t.dp.rodata", false,
31 SectionKind::getDataRel());
34 ReadOnlySection =
35 getELFSection(".dp.rodata", MCSectionELF::SHT_PROGBITS,
36 MCSectionELF::SHF_ALLOC | MCSectionELF::SHF_WRITE,
37 SectionKind::getDataRel());
3238 else
33 ReadOnlySection = getELFSection("\t.cp.rodata", false,
34 SectionKind::getReadOnly());
39 ReadOnlySection =
40 getELFSection(".cp.rodata", MCSectionELF::SHT_PROGBITS,
41 MCSectionELF::SHF_ALLOC, SectionKind::getReadOnly());
3542 }
0 ; RUN: llvm-as < %s | llc -mtriple=i386-unknown-linux-gnu | FileCheck %s -check-prefix=LINUX
1
2 declare i32 @foo()
3 @G0 = global i32 ()* @foo, section ".init_array"
4
5 ; LINUX: .section .init_array,"aw"
6 ; LINUX: .globl G0
7
8 @G1 = global i32 ()* @foo, section ".fini_array"
9
10 ; LINUX: .section .fini_array,"aw"
11 ; LINUX: .globl G1
12
13 @G2 = global i32 ()* @foo, section ".preinit_array"
14
15 ; LINUX: .section .preinit_array,"aw"
16 ; LINUX: .globl G2
17