History

linkage: Introduce new macros for assembler symbols

Introduce new C macros for annotations of functions and data in assembly. There is a long-standing mess in macros like ENTRY, END, ENDPROC and similar. They are used in different manners and sometimes incorrectly. So introduce macros with clear use to annotate assembly as follows: a) Support macros for the ones below SYM_T_FUNC -- type used by assembler to mark functions SYM_T_OBJECT -- type used by assembler to mark data SYM_T_NONE -- type used by assembler to mark entries of unknown type They are defined as STT_FUNC, STT_OBJECT, and STT_NOTYPE respectively. According to the gas manual, this is the most portable way. I am not sure about other assemblers, so this can be switched back to %function and %object if this turns into a problem. Architectures can also override them by something like ", @function" if they need. SYM_A_ALIGN, SYM_A_NONE -- align the symbol? SYM_L_GLOBAL, SYM_L_WEAK, SYM_L_LOCAL -- linkage of symbols b) Mostly internal annotations, used by the ones below SYM_ENTRY -- use only if you have to (for non-paired symbols) SYM_START -- use only if you have to (for paired symbols) SYM_END -- use only if you have to (for paired symbols) c) Annotations for code SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code SYM_INNER_LABEL -- only for labels in the middle of code SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one function SYM_FUNC_START_ALIAS -- use where there are two global names for one function SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed function SYM_FUNC_START -- use for global functions SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment SYM_FUNC_START_LOCAL -- use for local functions SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment SYM_FUNC_START_WEAK -- use for weak functions SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START, SYM_FUNC_START_WEAK, ... For functions with special (non-C) calling conventions: SYM_CODE_START -- use for non-C (special) functions SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment SYM_CODE_START_LOCAL -- use for local non-C (special) functions SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions, w/o alignment SYM_CODE_END -- the end of SYM_CODE_START_LOCAL or SYM_CODE_START d) For data SYM_DATA_START -- global data symbol SYM_DATA_START_LOCAL -- local data symbol SYM_DATA_END -- the end of the SYM_DATA_START symbol SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol SYM_DATA -- start+end wrapper around simple global data SYM_DATA_LOCAL -- start+end wrapper around simple local data ========== The macros allow to pair starts and ends of functions and mark functions correctly in the output ELF objects. All users of the old macros in x86 are converted to use these in further patches.

Jiri Slaby committed 7 years ago

Commit ffedeeb1 parent 30a24414 files · +468 −11Browse files

Showing the changes to include/linux (1 of 4 files). Show all

Unified · Split

include/linux/linkage.h+237−8
@@ -75,32 +75,58 @@ · 74 unmodified lines
7575
7676 #ifdef __ASSEMBLY__
7777
78+/* SYM_T_FUNC -- type used by assembler to mark functions */
79+#ifndef SYM_T_FUNC
80+#define SYM_T_FUNC STT_FUNC
81+#endif
82+
83+/* SYM_T_OBJECT -- type used by assembler to mark data */
84+#ifndef SYM_T_OBJECT
85+#define SYM_T_OBJECT STT_OBJECT
86+#endif
87+
88+/* SYM_T_NONE -- type used by assembler to mark entries of unknown type */
89+#ifndef SYM_T_NONE
90+#define SYM_T_NONE STT_NOTYPE
91+#endif
92+
93+/* SYM_A_* -- align the symbol? */
94+#define SYM_A_ALIGN ALIGN
95+#define SYM_A_NONE /* nothing */
96+
97+/* SYM_L_* -- linkage of symbols */
98+#define SYM_L_GLOBAL(name) .globl name
99+#define SYM_L_WEAK(name) .weak name
100+#define SYM_L_LOCAL(name) /* nothing */
101+
78102 #ifndef LINKER_SCRIPT
79103 #define ALIGN __ALIGN
80104 #define ALIGN_STR __ALIGN_STR
81105
106+/* === DEPRECATED annotations === */
107+
82108 #ifndef GLOBAL
109+/* deprecated, use SYM_DATA*, SYM_ENTRY, or similar */
83110 #define GLOBAL(name) \
84111 .globl name ASM_NL \
85112 name:
86113 #endif
87114
88115 #ifndef ENTRY
116+/* deprecated, use SYM_FUNC_START */
89117 #define ENTRY(name) \
90− .globl name ASM_NL \
91− ALIGN ASM_NL \
92− name:
118+ SYM_FUNC_START(name)
93119 #endif
94120 #endif /* LINKER_SCRIPT */
95121
96122 #ifndef WEAK
123+/* deprecated, use SYM_FUNC_START_WEAK* */
97124 #define WEAK(name) \
98− .weak name ASM_NL \
99− ALIGN ASM_NL \
100− name:
125+ SYM_FUNC_START_WEAK(name)
101126 #endif
102127
103128 #ifndef END
129+/* deprecated, use SYM_FUNC_END, SYM_DATA_END, or SYM_END */
104130 #define END(name) \
105131 .size name, .-name
106132 #endif
@@ -110,11 +136,214 @@ · 3 unmodified lines
110136 * static analysis tools such as stack depth analyzer.
111137 */
112138 #ifndef ENDPROC
139+/* deprecated, use SYM_FUNC_END */
113140 #define ENDPROC(name) \
114− .type name, @function ASM_NL \
115− END(name)
141+ SYM_FUNC_END(name)
142+#endif
143+
144+/* === generic annotations === */
145+
146+/* SYM_ENTRY -- use only if you have to for non-paired symbols */
147+#ifndef SYM_ENTRY
148+#define SYM_ENTRY(name, linkage, align...) \
149+ linkage(name) ASM_NL \
150+ align ASM_NL \
151+ name:
152+#endif
153+
154+/* SYM_START -- use only if you have to */
155+#ifndef SYM_START
156+#define SYM_START(name, linkage, align...) \
157+ SYM_ENTRY(name, linkage, align)
158+#endif
159+
160+/* SYM_END -- use only if you have to */
161+#ifndef SYM_END
162+#define SYM_END(name, sym_type) \
163+ .type name sym_type ASM_NL \
164+ .size name, .-name
165+#endif
166+
167+/* === code annotations === */
168+
169+/*
170+ * FUNC -- C-like functions (proper stack frame etc.)
171+ * CODE -- non-C code (e.g. irq handlers with different, special stack etc.)
172+ *
173+ * Objtool validates stack for FUNC, but not for CODE.
174+ * Objtool generates debug info for both FUNC & CODE, but needs special
175+ * annotations for each CODE's start (to describe the actual stack frame).
176+ *
177+ * ALIAS -- does not generate debug info -- the aliased function will
178+ */
179+
180+/* SYM_INNER_LABEL_ALIGN -- only for labels in the middle of code */
181+#ifndef SYM_INNER_LABEL_ALIGN
182+#define SYM_INNER_LABEL_ALIGN(name, linkage) \
183+ .type name SYM_T_NONE ASM_NL \
184+ SYM_ENTRY(name, linkage, SYM_A_ALIGN)
185+#endif
186+
187+/* SYM_INNER_LABEL -- only for labels in the middle of code */
188+#ifndef SYM_INNER_LABEL
189+#define SYM_INNER_LABEL(name, linkage) \
190+ .type name SYM_T_NONE ASM_NL \
191+ SYM_ENTRY(name, linkage, SYM_A_NONE)
192+#endif
193+
194+/*
195+ * SYM_FUNC_START_LOCAL_ALIAS -- use where there are two local names for one
196+ * function
197+ */
198+#ifndef SYM_FUNC_START_LOCAL_ALIAS
199+#define SYM_FUNC_START_LOCAL_ALIAS(name) \
200+ SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
201+#endif
202+
203+/*
204+ * SYM_FUNC_START_ALIAS -- use where there are two global names for one
205+ * function
206+ */
207+#ifndef SYM_FUNC_START_ALIAS
208+#define SYM_FUNC_START_ALIAS(name) \
209+ SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
210+#endif
211+
212+/* SYM_FUNC_START -- use for global functions */
213+#ifndef SYM_FUNC_START
214+/*
215+ * The same as SYM_FUNC_START_ALIAS, but we will need to distinguish these two
216+ * later.
217+ */
218+#define SYM_FUNC_START(name) \
219+ SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
220+#endif
221+
222+/* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
223+#ifndef SYM_FUNC_START_NOALIGN
224+#define SYM_FUNC_START_NOALIGN(name) \
225+ SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
226+#endif
227+
228+/* SYM_FUNC_START_LOCAL -- use for local functions */
229+#ifndef SYM_FUNC_START_LOCAL
230+/* the same as SYM_FUNC_START_LOCAL_ALIAS, see comment near SYM_FUNC_START */
231+#define SYM_FUNC_START_LOCAL(name) \
232+ SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
116233 #endif
117234
235+/* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
236+#ifndef SYM_FUNC_START_LOCAL_NOALIGN
237+#define SYM_FUNC_START_LOCAL_NOALIGN(name) \
238+ SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
118239 #endif
119240
241+/* SYM_FUNC_START_WEAK -- use for weak functions */
242+#ifndef SYM_FUNC_START_WEAK
243+#define SYM_FUNC_START_WEAK(name) \
244+ SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN)
120245 #endif
246+
247+/* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
248+#ifndef SYM_FUNC_START_WEAK_NOALIGN
249+#define SYM_FUNC_START_WEAK_NOALIGN(name) \
250+ SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
251+#endif
252+
253+/* SYM_FUNC_END_ALIAS -- the end of LOCAL_ALIASed or ALIASed function */
254+#ifndef SYM_FUNC_END_ALIAS
255+#define SYM_FUNC_END_ALIAS(name) \
256+ SYM_END(name, SYM_T_FUNC)
257+#endif
258+
259+/*
260+ * SYM_FUNC_END -- the end of SYM_FUNC_START_LOCAL, SYM_FUNC_START,
261+ * SYM_FUNC_START_WEAK, ...
262+ */
263+#ifndef SYM_FUNC_END
264+/* the same as SYM_FUNC_END_ALIAS, see comment near SYM_FUNC_START */
265+#define SYM_FUNC_END(name) \
266+ SYM_END(name, SYM_T_FUNC)
267+#endif
268+
269+/* SYM_CODE_START -- use for non-C (special) functions */
270+#ifndef SYM_CODE_START
271+#define SYM_CODE_START(name) \
272+ SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
273+#endif
274+
275+/* SYM_CODE_START_NOALIGN -- use for non-C (special) functions, w/o alignment */
276+#ifndef SYM_CODE_START_NOALIGN
277+#define SYM_CODE_START_NOALIGN(name) \
278+ SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
279+#endif
280+
281+/* SYM_CODE_START_LOCAL -- use for local non-C (special) functions */
282+#ifndef SYM_CODE_START_LOCAL
283+#define SYM_CODE_START_LOCAL(name) \
284+ SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN)
285+#endif
286+
287+/*
288+ * SYM_CODE_START_LOCAL_NOALIGN -- use for local non-C (special) functions,
289+ * w/o alignment
290+ */
291+#ifndef SYM_CODE_START_LOCAL_NOALIGN
292+#define SYM_CODE_START_LOCAL_NOALIGN(name) \
293+ SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
294+#endif
295+
296+/* SYM_CODE_END -- the end of SYM_CODE_START_LOCAL, SYM_CODE_START, ... */
297+#ifndef SYM_CODE_END
298+#define SYM_CODE_END(name) \
299+ SYM_END(name, SYM_T_NONE)
300+#endif
301+
302+/* === data annotations === */
303+
304+/* SYM_DATA_START -- global data symbol */
305+#ifndef SYM_DATA_START
306+#define SYM_DATA_START(name) \
307+ SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
308+#endif
309+
310+/* SYM_DATA_START -- local data symbol */
311+#ifndef SYM_DATA_START_LOCAL
312+#define SYM_DATA_START_LOCAL(name) \
313+ SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
314+#endif
315+
316+/* SYM_DATA_END -- the end of SYM_DATA_START symbol */
317+#ifndef SYM_DATA_END
318+#define SYM_DATA_END(name) \
319+ SYM_END(name, SYM_T_OBJECT)
320+#endif
321+
322+/* SYM_DATA_END_LABEL -- the labeled end of SYM_DATA_START symbol */
323+#ifndef SYM_DATA_END_LABEL
324+#define SYM_DATA_END_LABEL(name, linkage, label) \
325+ linkage(label) ASM_NL \
326+ .type label SYM_T_OBJECT ASM_NL \
327+ label: \
328+ SYM_END(name, SYM_T_OBJECT)
329+#endif
330+
331+/* SYM_DATA -- start+end wrapper around simple global data */
332+#ifndef SYM_DATA
333+#define SYM_DATA(name, data...) \
334+ SYM_DATA_START(name) ASM_NL \
335+ data ASM_NL \
336+ SYM_DATA_END(name)
337+#endif
338+
339+/* SYM_DATA_LOCAL -- start+end wrapper around simple local data */
340+#ifndef SYM_DATA_LOCAL
341+#define SYM_DATA_LOCAL(name, data...) \
342+ SYM_DATA_START_LOCAL(name) ASM_NL \
343+ data ASM_NL \
344+ SYM_DATA_END(name)
345+#endif
346+
347+#endif /* __ASSEMBLY__ */
348+
349+#endif /* _LINUX_LINKAGE_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t