@@ -67,25 +67,154 @@ namespace llvm {
67
67
raw_ostream &OS) const ;
68
68
};
69
69
70
+
71
+ // / MCSectionMachO - This represents a section on a Mach-O system (used by
72
+ // / Mac OS X). On a Mac system, these are also described in
73
+ // / /usr/include/mach-o/loader.h.
70
74
class MCSectionMachO : public MCSection {
71
- std::string Name;
75
+ char SegmentName[16 ]; // Not necessarily null terminated!
76
+ char SectionName[16 ]; // Not necessarily null terminated!
72
77
73
- // / IsDirective - This is true if the section name is a directive, not
74
- // / something that should be printed with ".section".
75
- // /
76
- // / FIXME: This is a hack. Switch to a semantic view of the section instead
77
- // / of a syntactic one.
78
- bool IsDirective;
78
+ // / TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES
79
+ // / field of a section, drawn from the enums below.
80
+ unsigned TypeAndAttributes;
81
+
82
+ // / Reserved2 - The 'reserved2' field of a section, used to represent the
83
+ // / size of stubs, for example.
84
+ unsigned Reserved2;
79
85
80
- MCSectionMachO (const StringRef &Name, bool IsDirective, SectionKind K,
81
- MCContext &Ctx);
86
+ MCSectionMachO (const StringRef &Segment, const StringRef &Section,
87
+ unsigned TAA, unsigned reserved2, SectionKind K)
88
+ : MCSection(K), TypeAndAttributes(TAA), Reserved2(reserved2) {
89
+ assert (Segment.size () <= 16 && Section.size () <= 16 &&
90
+ " Segment or section string too long" );
91
+ for (unsigned i = 0 ; i != 16 ; ++i) {
92
+ if (i < Segment.size ())
93
+ SegmentName[i] = Segment[i];
94
+ else
95
+ SegmentName[i] = 0 ;
96
+
97
+ if (i < Section.size ())
98
+ SectionName[i] = Section[i];
99
+ else
100
+ SectionName[i] = 0 ;
101
+ }
102
+ }
82
103
public:
83
104
84
- static MCSectionMachO *Create (const StringRef &Name, bool IsDirective,
105
+ static MCSectionMachO *Create (const StringRef &Segment,
106
+ const StringRef &Section,
107
+ unsigned TypeAndAttributes,
108
+ unsigned Reserved2,
85
109
SectionKind K, MCContext &Ctx);
110
+
111
+ // / These are the section type and attributes fields. A MachO section can
112
+ // / have only one Type, but can have any of the attributes specified.
113
+ enum {
114
+ // TypeAndAttributes bitmasks.
115
+ SECTION_TYPE = 0x000000FFU ,
116
+ SECTION_ATTRIBUTES = 0xFFFFFF00U ,
117
+
118
+ // Valid section types.
119
+
120
+ // / S_REGULAR - Regular section.
121
+ S_REGULAR = 0x00U ,
122
+ // / S_ZEROFILL - Zero fill on demand section.
123
+ S_ZEROFILL = 0x01U ,
124
+ // / S_CSTRING_LITERALS - Section with literal C strings.
125
+ S_CSTRING_LITERALS = 0x02U ,
126
+ // / S_4BYTE_LITERALS - Section with 4 byte literals.
127
+ S_4BYTE_LITERALS = 0x03U ,
128
+ // / S_8BYTE_LITERALS - Section with 8 byte literals.
129
+ S_8BYTE_LITERALS = 0x04U ,
130
+ // / S_LITERAL_POINTERS - Section with pointers to literals.
131
+ S_LITERAL_POINTERS = 0x05U ,
132
+ // / S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
133
+ S_NON_LAZY_SYMBOL_POINTERS = 0x06U ,
134
+ // / S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
135
+ S_LAZY_SYMBOL_POINTERS = 0x07U ,
136
+ // / S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
137
+ // / the Reserved2 field.
138
+ S_SYMBOL_STUBS = 0x08U ,
139
+ // / S_SYMBOL_STUBS - Section with only function pointers for
140
+ // / initialization.
141
+ S_MOD_INIT_FUNC_POINTERS = 0x09U ,
142
+ // / S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
143
+ // / termination.
144
+ S_MOD_TERM_FUNC_POINTERS = 0x0AU ,
145
+ // / S_COALESCED - Section contains symbols that are to be coalesced.
146
+ S_COALESCED = 0x0BU ,
147
+ // / S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
148
+ // / gigabytes).
149
+ S_GB_ZEROFILL = 0x0CU ,
150
+ // / S_INTERPOSING - Section with only pairs of function pointers for
151
+ // / interposing.
152
+ S_INTERPOSING = 0x0DU ,
153
+ // / S_16BYTE_LITERALS - Section with only 16 byte literals.
154
+ S_16BYTE_LITERALS = 0x0EU ,
155
+ // / S_DTRACE_DOF - Section contains DTrace Object Format.
156
+ S_DTRACE_DOF = 0x0FU ,
157
+ // / S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
158
+ // / lazy loaded dylibs.
159
+ S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10U ,
86
160
87
- const std::string &getName () const { return Name; }
88
- bool isDirective () const { return IsDirective; }
161
+ LAST_KNOWN_SECTION_TYPE = S_LAZY_DYLIB_SYMBOL_POINTERS,
162
+
163
+
164
+ // Valid section attributes.
165
+
166
+ // / S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
167
+ // / instructions.
168
+ S_ATTR_PURE_INSTRUCTIONS = 1U << 31 ,
169
+ // / S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
170
+ // / in a ranlib table of contents.
171
+ S_ATTR_NO_TOC = 1U << 30 ,
172
+ // / S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
173
+ // / in files with the MY_DYLDLINK flag.
174
+ S_ATTR_STRIP_STATIC_SYMS = 1U << 29 ,
175
+ // / S_ATTR_NO_DEAD_STRIP - No dead stripping.
176
+ S_ATTR_NO_DEAD_STRIP = 1U << 28 ,
177
+ // / S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
178
+ S_ATTR_LIVE_SUPPORT = 1U << 27 ,
179
+ // / S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
180
+ // / dyld.
181
+ S_ATTR_SELF_MODIFYING_CODE = 1U << 26 ,
182
+ // / S_ATTR_DEBUG - A debug section.
183
+ S_ATTR_DEBUG = 1U << 25 ,
184
+ // / S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
185
+ S_ATTR_SOME_INSTRUCTIONS = 1U << 10 ,
186
+ // / S_ATTR_EXT_RELOC - Section has external relocation entries.
187
+ S_ATTR_EXT_RELOC = 1U << 9 ,
188
+ // / S_ATTR_LOC_RELOC - Section has local relocation entries.
189
+ S_ATTR_LOC_RELOC = 1U << 8
190
+ };
191
+
192
+ StringRef getSegmentName () const {
193
+ // SegmentName is not necessarily null terminated!
194
+ if (SegmentName[15 ])
195
+ return StringRef (SegmentName, 16 );
196
+ return StringRef (SegmentName);
197
+ }
198
+ StringRef getSectionName () const {
199
+ // SectionName is not necessarily null terminated!
200
+ if (SectionName[15 ])
201
+ return StringRef (SectionName, 16 );
202
+ return StringRef (SectionName);
203
+ }
204
+
205
+ unsigned getTypeAndAttributes () const { return TypeAndAttributes; }
206
+
207
+
208
+ // / ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
209
+ // / This is a string that can appear after a .section directive in a mach-o
210
+ // / flavored .s file. If successful, this fills in the specified Out
211
+ // / parameters and returns an empty string. When an invalid section
212
+ // / specifier is present, this returns a string indicating the problem.
213
+ static std::string ParseSectionSpecifier (StringRef Spec, // In.
214
+ StringRef &Segment, // Out.
215
+ StringRef &Section, // Out.
216
+ unsigned &TAA, // Out.
217
+ unsigned &StubSize); // Out.
89
218
90
219
virtual void PrintSwitchToSection (const TargetAsmInfo &TAI,
91
220
raw_ostream &OS) const ;
0 commit comments