1 From f51ab1871655a9a96134c2636c37dcb5a6b01ac3 Mon Sep 17 00:00:00 2001
2 From: serge-sans-paille <sguelton@redhat.com>
3 Date: Mon, 22 Mar 2021 10:05:25 +0100
4 Subject: [PATCH] Make clangd CompletionModel usable even with non-standard
7 llvm supports specifying a non-standard layout where each project lies in its
8 own place. Do not assume a fixed layout and use the appropriate cmake variable
11 Differential Revision: https://reviews.llvm.org/D96787
13 clang-tools-extra/clangd/quality/CompletionModel.cmake | 4 ++--
14 1 file changed, 2 insertions(+), 2 deletions(-)
16 diff --git a/clang-tools-extra/clangd/quality/CompletionModel.cmake b/clang-tools-extra/clangd/quality/CompletionModel.cmake
17 index 60c6d2aa84330..41bc2ed1890b0 100644
18 --- a/tools/clang/tools/extra/clangd/quality/CompletionModel.cmake
19 +++ b/tools/clang/tools/extra/clangd/quality/CompletionModel.cmake
21 # will define a C++ class called ${cpp_class} - which may be a
22 # namespace-qualified class name.
23 function(gen_decision_forest model filename cpp_class)
24 - set(model_compiler ${CMAKE_SOURCE_DIR}/../clang-tools-extra/clangd/quality/CompletionModelCodegen.py)
26 + set(model_compiler ${LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR}/clangd/quality/CompletionModelCodegen.py)
28 set(output_dir ${CMAKE_CURRENT_BINARY_DIR})
29 set(header_file ${output_dir}/${filename}.h)
30 set(cpp_file ${output_dir}/${filename}.cpp)
31 diff -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
32 --- llvm-12.0.0.src.orig/tools/lld/MachO/mach-o/compact_unwind_encoding.h 1970-01-01 01:00:00.000000000 +0100
33 +++ llvm-12.0.0.src/tools/lld/MachO/mach-o/compact_unwind_encoding.h 2021-04-16 16:24:55.701577683 +0200
35 +//===------------------ mach-o/compact_unwind_encoding.h ------------------===//
37 +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
38 +// See https://llvm.org/LICENSE.txt for license information.
39 +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
42 +// Darwin's alternative to DWARF based unwind encodings.
44 +//===----------------------------------------------------------------------===//
47 +#ifndef __COMPACT_UNWIND_ENCODING__
48 +#define __COMPACT_UNWIND_ENCODING__
53 +// Compilers can emit standard DWARF FDEs in the __TEXT,__eh_frame section
54 +// of object files. Or compilers can emit compact unwind information in
55 +// the __LD,__compact_unwind section.
57 +// When the linker creates a final linked image, it will create a
58 +// __TEXT,__unwind_info section. This section is a small and fast way for the
59 +// runtime to access unwind info for any given function. If the compiler
60 +// emitted compact unwind info for the function, that compact unwind info will
61 +// be encoded in the __TEXT,__unwind_info section. If the compiler emitted
62 +// DWARF unwind info, the __TEXT,__unwind_info section will contain the offset
63 +// of the FDE in the __TEXT,__eh_frame section in the final linked image.
65 +// Note: Previously, the linker would transform some DWARF unwind infos into
66 +// compact unwind info. But that is fragile and no longer done.
70 +// The compact unwind endoding is a 32-bit value which encoded in an
71 +// architecture specific way, which registers to restore from where, and how
72 +// to unwind out of the function.
74 +typedef uint32_t compact_unwind_encoding_t;
77 +// architecture independent bits
79 + UNWIND_IS_NOT_FUNCTION_START = 0x80000000,
80 + UNWIND_HAS_LSDA = 0x40000000,
81 + UNWIND_PERSONALITY_MASK = 0x30000000,
92 +// 2-bit: personality index
94 +// 4-bits: 0=old, 1=ebp based, 2=stack-imm, 3=stack-ind, 4=DWARF
96 +// 15-bits (5*3-bits per reg) register permutation
97 +// 8-bits for stack offset
100 +// 3-bits stack adjust
101 +// 3-bits register count
102 +// 10-bits register permutation
105 + UNWIND_X86_MODE_MASK = 0x0F000000,
106 + UNWIND_X86_MODE_EBP_FRAME = 0x01000000,
107 + UNWIND_X86_MODE_STACK_IMMD = 0x02000000,
108 + UNWIND_X86_MODE_STACK_IND = 0x03000000,
109 + UNWIND_X86_MODE_DWARF = 0x04000000,
111 + UNWIND_X86_EBP_FRAME_REGISTERS = 0x00007FFF,
112 + UNWIND_X86_EBP_FRAME_OFFSET = 0x00FF0000,
114 + UNWIND_X86_FRAMELESS_STACK_SIZE = 0x00FF0000,
115 + UNWIND_X86_FRAMELESS_STACK_ADJUST = 0x0000E000,
116 + UNWIND_X86_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
117 + UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
119 + UNWIND_X86_DWARF_SECTION_OFFSET = 0x00FFFFFF,
123 + UNWIND_X86_REG_NONE = 0,
124 + UNWIND_X86_REG_EBX = 1,
125 + UNWIND_X86_REG_ECX = 2,
126 + UNWIND_X86_REG_EDX = 3,
127 + UNWIND_X86_REG_EDI = 4,
128 + UNWIND_X86_REG_ESI = 5,
129 + UNWIND_X86_REG_EBP = 6,
133 +// For x86 there are four modes for the compact unwind encoding:
134 +// UNWIND_X86_MODE_EBP_FRAME:
135 +// EBP based frame where EBP is push on stack immediately after return address,
136 +// then ESP is moved to EBP. Thus, to unwind ESP is restored with the current
137 +// EPB value, then EBP is restored by popping off the stack, and the return
138 +// is done by popping the stack once more into the pc.
139 +// All non-volatile registers that need to be restored must have been saved
140 +// in a small range in the stack that starts EBP-4 to EBP-1020. The offset/4
141 +// is encoded in the UNWIND_X86_EBP_FRAME_OFFSET bits. The registers saved
142 +// are encoded in the UNWIND_X86_EBP_FRAME_REGISTERS bits as five 3-bit entries.
143 +// Each entry contains which register to restore.
144 +// UNWIND_X86_MODE_STACK_IMMD:
145 +// A "frameless" (EBP not used as frame pointer) function with a small
146 +// constant stack size. To return, a constant (encoded in the compact
147 +// unwind encoding) is added to the ESP. Then the return is done by
148 +// popping the stack into the pc.
149 +// All non-volatile registers that need to be restored must have been saved
150 +// on the stack immediately after the return address. The stack_size/4 is
151 +// encoded in the UNWIND_X86_FRAMELESS_STACK_SIZE (max stack size is 1024).
152 +// The number of registers saved is encoded in UNWIND_X86_FRAMELESS_STACK_REG_COUNT.
153 +// UNWIND_X86_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
154 +// saved and their order.
155 +// UNWIND_X86_MODE_STACK_IND:
156 +// A "frameless" (EBP not used as frame pointer) function large constant
157 +// stack size. This case is like the previous, except the stack size is too
158 +// large to encode in the compact unwind encoding. Instead it requires that
159 +// the function contains "subl $nnnnnnnn,ESP" in its prolog. The compact
160 +// encoding contains the offset to the nnnnnnnn value in the function in
161 +// UNWIND_X86_FRAMELESS_STACK_SIZE.
162 +// UNWIND_X86_MODE_DWARF:
163 +// No compact unwind encoding is available. Instead the low 24-bits of the
164 +// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
165 +// This mode is never used in object files. It is only generated by the
166 +// linker in final linked images which have only DWARF unwind info for a
169 +// The permutation encoding is a Lehmer code sequence encoded into a
170 +// single variable-base number so we can encode the ordering of up to
171 +// six registers in a 10-bit space.
173 +// The following is the algorithm used to create the permutation encoding used
174 +// with frameless stacks. It is passed the number of registers to be saved and
175 +// an array of the register numbers saved.
177 +//uint32_t permute_encode(uint32_t registerCount, const uint32_t registers[6])
179 +// uint32_t renumregs[6];
180 +// for (int i=6-registerCount; i < 6; ++i) {
181 +// int countless = 0;
182 +// for (int j=6-registerCount; j < i; ++j) {
183 +// if ( registers[j] < registers[i] )
186 +// renumregs[i] = registers[i] - countless -1;
188 +// uint32_t permutationEncoding = 0;
189 +// switch ( registerCount ) {
191 +// permutationEncoding |= (120*renumregs[0] + 24*renumregs[1]
192 +// + 6*renumregs[2] + 2*renumregs[3]
196 +// permutationEncoding |= (120*renumregs[1] + 24*renumregs[2]
197 +// + 6*renumregs[3] + 2*renumregs[4]
201 +// permutationEncoding |= (60*renumregs[2] + 12*renumregs[3]
202 +// + 3*renumregs[4] + renumregs[5]);
205 +// permutationEncoding |= (20*renumregs[3] + 4*renumregs[4]
209 +// permutationEncoding |= (5*renumregs[4] + renumregs[5]);
212 +// permutationEncoding |= (renumregs[5]);
215 +// return permutationEncoding;
227 +// 2-bit: personality index
229 +// 4-bits: 0=old, 1=rbp based, 2=stack-imm, 3=stack-ind, 4=DWARF
231 +// 15-bits (5*3-bits per reg) register permutation
232 +// 8-bits for stack offset
234 +// 8-bits stack size
235 +// 3-bits stack adjust
236 +// 3-bits register count
237 +// 10-bits register permutation
240 + UNWIND_X86_64_MODE_MASK = 0x0F000000,
241 + UNWIND_X86_64_MODE_RBP_FRAME = 0x01000000,
242 + UNWIND_X86_64_MODE_STACK_IMMD = 0x02000000,
243 + UNWIND_X86_64_MODE_STACK_IND = 0x03000000,
244 + UNWIND_X86_64_MODE_DWARF = 0x04000000,
246 + UNWIND_X86_64_RBP_FRAME_REGISTERS = 0x00007FFF,
247 + UNWIND_X86_64_RBP_FRAME_OFFSET = 0x00FF0000,
249 + UNWIND_X86_64_FRAMELESS_STACK_SIZE = 0x00FF0000,
250 + UNWIND_X86_64_FRAMELESS_STACK_ADJUST = 0x0000E000,
251 + UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT = 0x00001C00,
252 + UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF,
254 + UNWIND_X86_64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
258 + UNWIND_X86_64_REG_NONE = 0,
259 + UNWIND_X86_64_REG_RBX = 1,
260 + UNWIND_X86_64_REG_R12 = 2,
261 + UNWIND_X86_64_REG_R13 = 3,
262 + UNWIND_X86_64_REG_R14 = 4,
263 + UNWIND_X86_64_REG_R15 = 5,
264 + UNWIND_X86_64_REG_RBP = 6,
267 +// For x86_64 there are four modes for the compact unwind encoding:
268 +// UNWIND_X86_64_MODE_RBP_FRAME:
269 +// RBP based frame where RBP is push on stack immediately after return address,
270 +// then RSP is moved to RBP. Thus, to unwind RSP is restored with the current
271 +// EPB value, then RBP is restored by popping off the stack, and the return
272 +// is done by popping the stack once more into the pc.
273 +// All non-volatile registers that need to be restored must have been saved
274 +// in a small range in the stack that starts RBP-8 to RBP-2040. The offset/8
275 +// is encoded in the UNWIND_X86_64_RBP_FRAME_OFFSET bits. The registers saved
276 +// are encoded in the UNWIND_X86_64_RBP_FRAME_REGISTERS bits as five 3-bit entries.
277 +// Each entry contains which register to restore.
278 +// UNWIND_X86_64_MODE_STACK_IMMD:
279 +// A "frameless" (RBP not used as frame pointer) function with a small
280 +// constant stack size. To return, a constant (encoded in the compact
281 +// unwind encoding) is added to the RSP. Then the return is done by
282 +// popping the stack into the pc.
283 +// All non-volatile registers that need to be restored must have been saved
284 +// on the stack immediately after the return address. The stack_size/8 is
285 +// encoded in the UNWIND_X86_64_FRAMELESS_STACK_SIZE (max stack size is 2048).
286 +// The number of registers saved is encoded in UNWIND_X86_64_FRAMELESS_STACK_REG_COUNT.
287 +// UNWIND_X86_64_FRAMELESS_STACK_REG_PERMUTATION constains which registers were
288 +// saved and their order.
289 +// UNWIND_X86_64_MODE_STACK_IND:
290 +// A "frameless" (RBP not used as frame pointer) function large constant
291 +// stack size. This case is like the previous, except the stack size is too
292 +// large to encode in the compact unwind encoding. Instead it requires that
293 +// the function contains "subq $nnnnnnnn,RSP" in its prolog. The compact
294 +// encoding contains the offset to the nnnnnnnn value in the function in
295 +// UNWIND_X86_64_FRAMELESS_STACK_SIZE.
296 +// UNWIND_X86_64_MODE_DWARF:
297 +// No compact unwind encoding is available. Instead the low 24-bits of the
298 +// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
299 +// This mode is never used in object files. It is only generated by the
300 +// linker in final linked images which have only DWARF unwind info for a
309 +// 2-bit: personality index
311 +// 4-bits: 4=frame-based, 3=DWARF, 2=frameless
313 +// 12-bits of stack size
315 +// 4-bits D reg pairs saved
316 +// 5-bits X reg pairs saved
318 +// 24-bits offset of DWARF FDE in __eh_frame section
321 + UNWIND_ARM64_MODE_MASK = 0x0F000000,
322 + UNWIND_ARM64_MODE_FRAMELESS = 0x02000000,
323 + UNWIND_ARM64_MODE_DWARF = 0x03000000,
324 + UNWIND_ARM64_MODE_FRAME = 0x04000000,
326 + UNWIND_ARM64_FRAME_X19_X20_PAIR = 0x00000001,
327 + UNWIND_ARM64_FRAME_X21_X22_PAIR = 0x00000002,
328 + UNWIND_ARM64_FRAME_X23_X24_PAIR = 0x00000004,
329 + UNWIND_ARM64_FRAME_X25_X26_PAIR = 0x00000008,
330 + UNWIND_ARM64_FRAME_X27_X28_PAIR = 0x00000010,
331 + UNWIND_ARM64_FRAME_D8_D9_PAIR = 0x00000100,
332 + UNWIND_ARM64_FRAME_D10_D11_PAIR = 0x00000200,
333 + UNWIND_ARM64_FRAME_D12_D13_PAIR = 0x00000400,
334 + UNWIND_ARM64_FRAME_D14_D15_PAIR = 0x00000800,
336 + UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK = 0x00FFF000,
337 + UNWIND_ARM64_DWARF_SECTION_OFFSET = 0x00FFFFFF,
339 +// For arm64 there are three modes for the compact unwind encoding:
340 +// UNWIND_ARM64_MODE_FRAME:
341 +// This is a standard arm64 prolog where FP/LR are immediately pushed on the
342 +// stack, then SP is copied to FP. If there are any non-volatile registers
343 +// saved, then are copied into the stack frame in pairs in a contiguous
344 +// range right below the saved FP/LR pair. Any subset of the five X pairs
345 +// and four D pairs can be saved, but the memory layout must be in register
347 +// UNWIND_ARM64_MODE_FRAMELESS:
348 +// A "frameless" leaf function, where FP/LR are not saved. The return address
349 +// remains in LR throughout the function. If any non-volatile registers
350 +// are saved, they must be pushed onto the stack before any stack space is
351 +// allocated for local variables. The stack sized (including any saved
352 +// non-volatile registers) divided by 16 is encoded in the bits
353 +// UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK.
354 +// UNWIND_ARM64_MODE_DWARF:
355 +// No compact unwind encoding is available. Instead the low 24-bits of the
356 +// compact encoding is the offset of the DWARF FDE in the __eh_frame section.
357 +// This mode is never used in object files. It is only generated by the
358 +// linker in final linked images which have only DWARF unwind info for a
366 +////////////////////////////////////////////////////////////////////////////////
368 +// Relocatable Object Files: __LD,__compact_unwind
370 +////////////////////////////////////////////////////////////////////////////////
373 +// A compiler can generated compact unwind information for a function by adding
374 +// a "row" to the __LD,__compact_unwind section. This section has the
375 +// S_ATTR_DEBUG bit set, so the section will be ignored by older linkers.
376 +// It is removed by the new linker, so never ends up in final executables.
377 +// This section is a table, initially with one row per function (that needs
378 +// unwind info). The table columns and some conceptual entries are:
380 +// range-start pointer to start of function/range
382 +// compact-unwind-encoding 32-bit encoding
383 +// personality-function or zero if no personality function
384 +// lsda or zero if no LSDA data
386 +// The length and encoding fields are 32-bits. The other are all pointer sized.
388 +// In x86_64 assembly, these entry would look like:
390 +// .section __LD,__compact_unwind,regular,debug
392 +// #compact unwind for _foo
394 +// .set L1,LfooEnd-_foo
400 +// #compact unwind for _bar
402 +// .set L2,LbarEnd-_bar
405 +// .quad __gxx_personality
406 +// .quad except_tab1
409 +// Notes: There is no need for any labels in the the __compact_unwind section.
410 +// The use of the .set directive is to force the evaluation of the
411 +// range-length at assembly time, instead of generating relocations.
413 +// To support future compiler optimizations where which non-volatile registers
414 +// are saved changes within a function (e.g. delay saving non-volatiles until
415 +// necessary), there can by multiple lines in the __compact_unwind table for one
416 +// function, each with a different (non-overlapping) range and each with
417 +// different compact unwind encodings that correspond to the non-volatiles
418 +// saved at that range of the function.
420 +// If a particular function is so wacky that there is no compact unwind way
421 +// to encode it, then the compiler can emit traditional DWARF unwind info.
422 +// The runtime will use which ever is available.
424 +// Runtime support for compact unwind encodings are only available on 10.6
425 +// and later. So, the compiler should not generate it when targeting pre-10.6.
430 +////////////////////////////////////////////////////////////////////////////////
432 +// Final Linked Images: __TEXT,__unwind_info
434 +////////////////////////////////////////////////////////////////////////////////
437 +// The __TEXT,__unwind_info section is laid out for an efficient two level lookup.
438 +// The header of the section contains a coarse index that maps function address
439 +// to the page (4096 byte block) containing the unwind info for that function.
442 +#define UNWIND_SECTION_VERSION 1
443 +struct unwind_info_section_header
445 + uint32_t version; // UNWIND_SECTION_VERSION
446 + uint32_t commonEncodingsArraySectionOffset;
447 + uint32_t commonEncodingsArrayCount;
448 + uint32_t personalityArraySectionOffset;
449 + uint32_t personalityArrayCount;
450 + uint32_t indexSectionOffset;
451 + uint32_t indexCount;
452 + // compact_unwind_encoding_t[]
453 + // uint32_t personalities[]
454 + // unwind_info_section_header_index_entry[]
455 + // unwind_info_section_header_lsda_index_entry[]
458 +struct unwind_info_section_header_index_entry
460 + uint32_t functionOffset;
461 + uint32_t secondLevelPagesSectionOffset; // section offset to start of regular or compress page
462 + uint32_t lsdaIndexArraySectionOffset; // section offset to start of lsda_index array for this range
465 +struct unwind_info_section_header_lsda_index_entry
467 + uint32_t functionOffset;
468 + uint32_t lsdaOffset;
472 +// There are two kinds of second level index pages: regular and compressed.
473 +// A compressed page can hold up to 1021 entries, but it cannot be used
474 +// if too many different encoding types are used. The regular page holds
478 +struct unwind_info_regular_second_level_entry
480 + uint32_t functionOffset;
481 + compact_unwind_encoding_t encoding;
484 +#define UNWIND_SECOND_LEVEL_REGULAR 2
485 +struct unwind_info_regular_second_level_page_header
487 + uint32_t kind; // UNWIND_SECOND_LEVEL_REGULAR
488 + uint16_t entryPageOffset;
489 + uint16_t entryCount;
493 +#define UNWIND_SECOND_LEVEL_COMPRESSED 3
494 +struct unwind_info_compressed_second_level_page_header
496 + uint32_t kind; // UNWIND_SECOND_LEVEL_COMPRESSED
497 + uint16_t entryPageOffset;
498 + uint16_t entryCount;
499 + uint16_t encodingsPageOffset;
500 + uint16_t encodingsCount;
501 + // 32-bit entry array
505 +#define UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(entry) (entry & 0x00FFFFFF)
506 +#define UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(entry) ((entry >> 24) & 0xFF)