]> git.pld-linux.org Git - packages/llvm.git/blame - llvm12-build_fixes.patch
- added libexecdir patch, consistently package binaries from both scan-build in libex...
[packages/llvm.git] / llvm12-build_fixes.patch
CommitLineData
40bef2a3
JP
1diff -urN llvm-12.0.0.src.orig/tools/lld/MachO/mach-o/compact_unwind_encoding.h llvm-12.0.0.src/tools/lld/MachO/mach-o/compact_unwind_encoding.h
2--- llvm-12.0.0.src.orig/tools/lld/MachO/mach-o/compact_unwind_encoding.h 1970-01-01 01:00:00.000000000 +0100
3+++ llvm-12.0.0.src/tools/lld/MachO/mach-o/compact_unwind_encoding.h 2021-04-16 16:24:55.701577683 +0200
4@@ -0,0 +1,477 @@
5+//===------------------ mach-o/compact_unwind_encoding.h ------------------===//
6+//
7+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8+// See https://llvm.org/LICENSE.txt for license information.
9+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10+//
11+//
12+// Darwin's alternative to DWARF based unwind encodings.
13+//
14+//===----------------------------------------------------------------------===//
15+
16+
17+#ifndef __COMPACT_UNWIND_ENCODING__
18+#define __COMPACT_UNWIND_ENCODING__
19+
20+#include <stdint.h>
21+
22+//
23+// Compilers can emit standard DWARF FDEs in the __TEXT,__eh_frame section
24+// of object files. Or compilers can emit compact unwind information in
25+// the __LD,__compact_unwind section.
26+//
27+// When the linker creates a final linked image, it will create a
28+// __TEXT,__unwind_info section. This section is a small and fast way for the
29+// runtime to access unwind info for any given function. If the compiler
30+// emitted compact unwind info for the function, that compact unwind info will
31+// be encoded in the __TEXT,__unwind_info section. If the compiler emitted
32+// DWARF unwind info, the __TEXT,__unwind_info section will contain the offset
33+// of the FDE in the __TEXT,__eh_frame section in the final linked image.
34+//
35+// Note: Previously, the linker would transform some DWARF unwind infos into
36+// compact unwind info. But that is fragile and no longer done.
37+
38+
39+//
40+// The compact unwind endoding is a 32-bit value which encoded in an
41+// architecture specific way, which registers to restore from where, and how
42+// to unwind out of the function.
43+//
44+typedef uint32_t compact_unwind_encoding_t;
45+
46+
47+// architecture independent bits
48+enum {
49+ UNWIND_IS_NOT_FUNCTION_START = 0x80000000,
50+ UNWIND_HAS_LSDA = 0x40000000,
51+ UNWIND_PERSONALITY_MASK = 0x30000000,
52+};
53+
54+
55+
56+
57+//
58+// x86
59+//
60+// 1-bit: start
61+// 1-bit: has lsda
62+// 2-bit: personality index
63+//
64+// 4-bits: 0=old, 1=ebp based, 2=stack-imm, 3=stack-ind, 4=DWARF
65+// ebp based:
66+// 15-bits (5*3-bits per reg) register permutation
67+// 8-bits for stack offset
68+// frameless:
69+// 8-bits stack size
70+// 3-bits stack adjust
71+// 3-bits register count
72+// 10-bits register permutation
73+//
74+enum {
75+ UNWIND_X86_MODE_MASK = 0x0F000000,
76+ UNWIND_X86_MODE_EBP_FRAME = 0x01000000,
77+ UNWIND_X86_MODE_STACK_IMMD = 0x02000000,
78+ UNWIND_X86_MODE_STACK_IND = 0x03000000,
79+ UNWIND_X86_MODE_DWARF = 0x04000000,
80+
81+ UNWIND_X86_EBP_FRAME_REGISTERS = 0x00007FFF,
82+ UNWIND_X86_EBP_FRAME_OFFSET = 0x00FF0000,
83+
84+ UNWIND_X86_FRAMELESS_STACK_SIZE = 0x00FF0000,
85+ UNWIND_X86_FRAMELESS_STACK_ADJUST = 0x0000E000,
86+ UNWIND_X86_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
87+ UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
88+
89+ UNWIND_X86_DWARF_SECTION_OFFSET = 0x00FFFFFF,
90+};
91+
92+enum {
93+ UNWIND_X86_REG_NONE = 0,
94+ UNWIND_X86_REG_EBX = 1,
95+ UNWIND_X86_REG_ECX = 2,
96+ UNWIND_X86_REG_EDX = 3,
97+ UNWIND_X86_REG_EDI = 4,
98+ UNWIND_X86_REG_ESI = 5,
99+ UNWIND_X86_REG_EBP = 6,
100+};
101+
102+//
103+// For x86 there are four modes for the compact unwind encoding:
104+// UNWIND_X86_MODE_EBP_FRAME:
105+// EBP based frame where EBP is push on stack immediately after return address,
106+// then ESP is moved to EBP. Thus, to unwind ESP is restored with the current
107+// EPB value, then EBP is restored by popping off the stack, and the return
108+// is done by popping the stack once more into the pc.
109+// All non-volatile registers that need to be restored must have been saved
110+// in a small range in the stack that starts EBP-4 to EBP-1020. The offset/4
111+// is encoded in the UNWIND_X86_EBP_FRAME_OFFSET bits. The registers saved
112+// are encoded in the UNWIND_X86_EBP_FRAME_REGISTERS bits as five 3-bit entries.
113+// Each entry contains which register to restore.
114+// UNWIND_X86_MODE_STACK_IMMD:
115+// A "frameless" (EBP not used as frame pointer) function with a small
116+// constant stack size. To return, a constant (encoded in the compact
117+// unwind encoding) is added to the ESP. Then the return is done by
118+// popping the stack into the pc.
119+// All non-volatile registers that need to be restored must have been saved
120+// on the stack immediately after the return address. The stack_size/4 is
121+// encoded in the UNWIND_X86_FRAMELESS_STACK_SIZE (max stack size is 1024).
122+// The number of registers saved is encoded in UNWIND_X86_FRAMELESS_STACK_REG_COUNT.
123+// UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
124+// saved and their order.
125+// UNWIND_X86_MODE_STACK_IND:
126+// A "frameless" (EBP not used as frame pointer) function large constant
127+// stack size. This case is like the previous, except the stack size is too
128+// large to encode in the compact unwind encoding. Instead it requires that
129+// the function contains "subl $nnnnnnnn,ESP" in its prolog. The compact
130+// encoding contains the offset to the nnnnnnnn value in the function in
131+// UNWIND_X86_FRAMELESS_STACK_SIZE.
132+// UNWIND_X86_MODE_DWARF:
133+// No compact unwind encoding is available. Instead the low 24-bits of the
134+// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
135+// This mode is never used in object files. It is only generated by the
136+// linker in final linked images which have only DWARF unwind info for a
137+// function.
138+//
139+// The permutation encoding is a Lehmer code sequence encoded into a
140+// single variable-base number so we can encode the ordering of up to
141+// six registers in a 10-bit space.
142+//
143+// The following is the algorithm used to create the permutation encoding used
144+// with frameless stacks. It is passed the number of registers to be saved and
145+// an array of the register numbers saved.
146+//
147+//uint32_t permute_encode(uint32_t registerCount, const uint32_t registers[6])
148+//{
149+// uint32_t renumregs[6];
150+// for (int i=6-registerCount; i < 6; ++i) {
151+// int countless = 0;
152+// for (int j=6-registerCount; j < i; ++j) {
153+// if ( registers[j] < registers[i] )
154+// ++countless;
155+// }
156+// renumregs[i] = registers[i] - countless -1;
157+// }
158+// uint32_t permutationEncoding = 0;
159+// switch ( registerCount ) {
160+// case 6:
161+// permutationEncoding |= (120*renumregs[0] + 24*renumregs[1]
162+// + 6*renumregs[2] + 2*renumregs[3]
163+// + renumregs[4]);
164+// break;
165+// case 5:
166+// permutationEncoding |= (120*renumregs[1] + 24*renumregs[2]
167+// + 6*renumregs[3] + 2*renumregs[4]
168+// + renumregs[5]);
169+// break;
170+// case 4:
171+// permutationEncoding |= (60*renumregs[2] + 12*renumregs[3]
172+// + 3*renumregs[4] + renumregs[5]);
173+// break;
174+// case 3:
175+// permutationEncoding |= (20*renumregs[3] + 4*renumregs[4]
176+// + renumregs[5]);
177+// break;
178+// case 2:
179+// permutationEncoding |= (5*renumregs[4] + renumregs[5]);
180+// break;
181+// case 1:
182+// permutationEncoding |= (renumregs[5]);
183+// break;
184+// }
185+// return permutationEncoding;
186+//}
187+//
188+
189+
190+
191+
192+//
193+// x86_64
194+//
195+// 1-bit: start
196+// 1-bit: has lsda
197+// 2-bit: personality index
198+//
199+// 4-bits: 0=old, 1=rbp based, 2=stack-imm, 3=stack-ind, 4=DWARF
200+// rbp based:
201+// 15-bits (5*3-bits per reg) register permutation
202+// 8-bits for stack offset
203+// frameless:
204+// 8-bits stack size
205+// 3-bits stack adjust
206+// 3-bits register count
207+// 10-bits register permutation
208+//
209+enum {
210+ UNWIND_X86_64_MODE_MASK = 0x0F000000,
211+ UNWIND_X86_64_MODE_RBP_FRAME = 0x01000000,
212+ UNWIND_X86_64_MODE_STACK_IMMD = 0x02000000,
213+ UNWIND_X86_64_MODE_STACK_IND = 0x03000000,
214+ UNWIND_X86_64_MODE_DWARF = 0x04000000,
215+
216+ UNWIND_X86_64_RBP_FRAME_REGISTERS = 0x00007FFF,
217+ UNWIND_X86_64_RBP_FRAME_OFFSET = 0x00FF0000,
218+
219+ UNWIND_X86_64_FRAMELESS_STACK_SIZE = 0x00FF0000,
220+ UNWIND_X86_64_FRAMELESS_STACK_ADJUST = 0x0000E000,
221+ UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
222+ UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
223+
224+ UNWIND_X86_64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
225+};
226+
227+enum {
228+ UNWIND_X86_64_REG_NONE = 0,
229+ UNWIND_X86_64_REG_RBX = 1,
230+ UNWIND_X86_64_REG_R12 = 2,
231+ UNWIND_X86_64_REG_R13 = 3,
232+ UNWIND_X86_64_REG_R14 = 4,
233+ UNWIND_X86_64_REG_R15 = 5,
234+ UNWIND_X86_64_REG_RBP = 6,
235+};
236+//
237+// For x86_64 there are four modes for the compact unwind encoding:
238+// UNWIND_X86_64_MODE_RBP_FRAME:
239+// RBP based frame where RBP is push on stack immediately after return address,
240+// then RSP is moved to RBP. Thus, to unwind RSP is restored with the current
241+// EPB value, then RBP is restored by popping off the stack, and the return
242+// is done by popping the stack once more into the pc.
243+// All non-volatile registers that need to be restored must have been saved
244+// in a small range in the stack that starts RBP-8 to RBP-2040. The offset/8
245+// is encoded in the UNWIND_X86_64_RBP_FRAME_OFFSET bits. The registers saved
246+// are encoded in the UNWIND_X86_64_RBP_FRAME_REGISTERS bits as five 3-bit entries.
247+// Each entry contains which register to restore.
248+// UNWIND_X86_64_MODE_STACK_IMMD:
249+// A "frameless" (RBP not used as frame pointer) function with a small
250+// constant stack size. To return, a constant (encoded in the compact
251+// unwind encoding) is added to the RSP. Then the return is done by
252+// popping the stack into the pc.
253+// All non-volatile registers that need to be restored must have been saved
254+// on the stack immediately after the return address. The stack_size/8 is
255+// encoded in the UNWIND_X86_64_FRAMELESS_STACK_SIZE (max stack size is 2048).
256+// The number of registers saved is encoded in UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT.
257+// UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
258+// saved and their order.
259+// UNWIND_X86_64_MODE_STACK_IND:
260+// A "frameless" (RBP not used as frame pointer) function large constant
261+// stack size. This case is like the previous, except the stack size is too
262+// large to encode in the compact unwind encoding. Instead it requires that
263+// the function contains "subq $nnnnnnnn,RSP" in its prolog. The compact
264+// encoding contains the offset to the nnnnnnnn value in the function in
265+// UNWIND_X86_64_FRAMELESS_STACK_SIZE.
266+// UNWIND_X86_64_MODE_DWARF:
267+// No compact unwind encoding is available. Instead the low 24-bits of the
268+// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
269+// This mode is never used in object files. It is only generated by the
270+// linker in final linked images which have only DWARF unwind info for a
271+// function.
272+//
273+
274+
275+// ARM64
276+//
277+// 1-bit: start
278+// 1-bit: has lsda
279+// 2-bit: personality index
280+//
281+// 4-bits: 4=frame-based, 3=DWARF, 2=frameless
282+// frameless:
283+// 12-bits of stack size
284+// frame-based:
285+// 4-bits D reg pairs saved
286+// 5-bits X reg pairs saved
287+// DWARF:
288+// 24-bits offset of DWARF FDE in __eh_frame section
289+//
290+enum {
291+ UNWIND_ARM64_MODE_MASK = 0x0F000000,
292+ UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
293+ UNWIND_ARM64_MODE_DWARF = 0x03000000,
294+ UNWIND_ARM64_MODE_FRAME = 0x04000000,
295+
296+ UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
297+ UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
298+ UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
299+ UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
300+ UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
301+ UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
302+ UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
303+ UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
304+ UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800,
305+
306+ UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK = 0x00FFF000,
307+ UNWIND_ARM64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
308+};
309+// For arm64 there are three modes for the compact unwind encoding:
310+// UNWIND_ARM64_MODE_FRAME:
311+// This is a standard arm64 prolog where FP/LR are immediately pushed on the
312+// stack, then SP is copied to FP. If there are any non-volatile registers
313+// saved, then are copied into the stack frame in pairs in a contiguous
314+// range right below the saved FP/LR pair. Any subset of the five X pairs
315+// and four D pairs can be saved, but the memory layout must be in register
316+// number order.
317+// UNWIND_ARM64_MODE_FRAMELESS:
318+// A "frameless" leaf function, where FP/LR are not saved. The return address
319+// remains in LR throughout the function. If any non-volatile registers
320+// are saved, they must be pushed onto the stack before any stack space is
321+// allocated for local variables. The stack sized (including any saved
322+// non-volatile registers) divided by 16 is encoded in the bits
323+// UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK.
324+// UNWIND_ARM64_MODE_DWARF:
325+// No compact unwind encoding is available. Instead the low 24-bits of the
326+// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
327+// This mode is never used in object files. It is only generated by the
328+// linker in final linked images which have only DWARF unwind info for a
329+// function.
330+//
331+
332+
333+
334+
335+
336+////////////////////////////////////////////////////////////////////////////////
337+//
338+// Relocatable Object Files: __LD,__compact_unwind
339+//
340+////////////////////////////////////////////////////////////////////////////////
341+
342+//
343+// A compiler can generated compact unwind information for a function by adding
344+// a "row" to the __LD,__compact_unwind section. This section has the
345+// S_ATTR_DEBUG bit set, so the section will be ignored by older linkers.
346+// It is removed by the new linker, so never ends up in final executables.
347+// This section is a table, initially with one row per function (that needs
348+// unwind info). The table columns and some conceptual entries are:
349+//
350+// range-start pointer to start of function/range
351+// range-length
352+// compact-unwind-encoding 32-bit encoding
353+// personality-function or zero if no personality function
354+// lsda or zero if no LSDA data
355+//
356+// The length and encoding fields are 32-bits. The other are all pointer sized.
357+//
358+// In x86_64 assembly, these entry would look like:
359+//
360+// .section __LD,__compact_unwind,regular,debug
361+//
362+// #compact unwind for _foo
363+// .quad _foo
364+// .set L1,LfooEnd-_foo
365+// .long L1
366+// .long 0x01010001
367+// .quad 0
368+// .quad 0
369+//
370+// #compact unwind for _bar
371+// .quad _bar
372+// .set L2,LbarEnd-_bar
373+// .long L2
374+// .long 0x01020011
375+// .quad __gxx_personality
376+// .quad except_tab1
377+//
378+//
379+// Notes: There is no need for any labels in the the __compact_unwind section.
380+// The use of the .set directive is to force the evaluation of the
381+// range-length at assembly time, instead of generating relocations.
382+//
383+// To support future compiler optimizations where which non-volatile registers
384+// are saved changes within a function (e.g. delay saving non-volatiles until
385+// necessary), there can by multiple lines in the __compact_unwind table for one
386+// function, each with a different (non-overlapping) range and each with
387+// different compact unwind encodings that correspond to the non-volatiles
388+// saved at that range of the function.
389+//
390+// If a particular function is so wacky that there is no compact unwind way
391+// to encode it, then the compiler can emit traditional DWARF unwind info.
392+// The runtime will use which ever is available.
393+//
394+// Runtime support for compact unwind encodings are only available on 10.6
395+// and later. So, the compiler should not generate it when targeting pre-10.6.
396+
397+
398+
399+
400+////////////////////////////////////////////////////////////////////////////////
401+//
402+// Final Linked Images: __TEXT,__unwind_info
403+//
404+////////////////////////////////////////////////////////////////////////////////
405+
406+//
407+// The __TEXT,__unwind_info section is laid out for an efficient two level lookup.
408+// The header of the section contains a coarse index that maps function address
409+// to the page (4096 byte block) containing the unwind info for that function.
410+//
411+
412+#define UNWIND_SECTION_VERSION 1
413+struct unwind_info_section_header
414+{
415+ uint32_t version; // UNWIND_SECTION_VERSION
416+ uint32_t commonEncodingsArraySectionOffset;
417+ uint32_t commonEncodingsArrayCount;
418+ uint32_t personalityArraySectionOffset;
419+ uint32_t personalityArrayCount;
420+ uint32_t indexSectionOffset;
421+ uint32_t indexCount;
422+ // compact_unwind_encoding_t[]
423+ // uint32_t personalities[]
424+ // unwind_info_section_header_index_entry[]
425+ // unwind_info_section_header_lsda_index_entry[]
426+};
427+
428+struct unwind_info_section_header_index_entry
429+{
430+ uint32_t functionOffset;
431+ uint32_t secondLevelPagesSectionOffset; // section offset to start of regular or compress page
432+ uint32_t lsdaIndexArraySectionOffset; // section offset to start of lsda_index array for this range
433+};
434+
435+struct unwind_info_section_header_lsda_index_entry
436+{
437+ uint32_t functionOffset;
438+ uint32_t lsdaOffset;
439+};
440+
441+//
442+// There are two kinds of second level index pages: regular and compressed.
443+// A compressed page can hold up to 1021 entries, but it cannot be used
444+// if too many different encoding types are used. The regular page holds
445+// 511 entries.
446+//
447+
448+struct unwind_info_regular_second_level_entry
449+{
450+ uint32_t functionOffset;
451+ compact_unwind_encoding_t encoding;
452+};
453+
454+#define UNWIND_SECOND_LEVEL_REGULAR 2
455+struct unwind_info_regular_second_level_page_header
456+{
457+ uint32_t kind; // UNWIND_SECOND_LEVEL_REGULAR
458+ uint16_t entryPageOffset;
459+ uint16_t entryCount;
460+ // entry array
461+};
462+
463+#define UNWIND_SECOND_LEVEL_COMPRESSED 3
464+struct unwind_info_compressed_second_level_page_header
465+{
466+ uint32_t kind; // UNWIND_SECOND_LEVEL_COMPRESSED
467+ uint16_t entryPageOffset;
468+ uint16_t entryCount;
469+ uint16_t encodingsPageOffset;
470+ uint16_t encodingsCount;
471+ // 32-bit entry array
472+ // encodings array
473+};
474+
475+#define UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(entry) (entry & 0x00FFFFFF)
476+#define UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(entry) ((entry >> 24) & 0xFF)
477+
478+
479+
480+#endif
481+
This page took 0.133625 seconds and 4 git commands to generate.