mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
203bfa2f6b
The CTF variable section is an optional (usually-not-present) section in the CTF dict which contains name -> type mappings corresponding to data symbols that are present in the linker input but not in the output symbol table: the idea is that programs that use their own symbol- resolution mechanisms can use this section to look up the types of symbols they have found using their own mechanism. Because these removed symbols (mostly static variables, functions, etc) all have names that are unlikely to appear in the ELF symtab and because very few programs have their own symbol-resolution mechanisms, a special linker flag (--ctf-variables) is needed to emit this section. Historically, we emitted only removed data symbols into the variable section. This seemed to make sense at the time, but in hindsight it really doesn't: functions are symbols too, and a C program can look them up just like any other type. So extend the variable section so that it contains all static function symbols too (if it is emitted at all), with types of kind CTF_K_FUNCTION. This is a little fiddly. We relied on compiler assistance for data symbols: the compiler simply emits all data symbols twice, once into the symtypetab as an indexed symbol and once into the variable section. Rather than wait for a suitably adjusted compiler that does the same for function symbols, we can pluck unreported function symbols out of the symtab and add them to the variable section ourselves. While we're at it, we do the same with data symbols: this is redundant right now because the compiler does it, but it costs very little time and lets the compiler drop this kludge and save a little space in .o files. include/ * ctf.h: Mention the new things we can see in the variable section. ld/ * testsuite/ld-ctf/data-func-conflicted-vars.d: New test. libctf/ * ctf-link.c (ctf_link_deduplicating_variables): Duplicate symbols into the variable section too. * ctf-serialize.c (symtypetab_delete_nonstatic_vars): Rename to... (symtypetab_delete_nonstatics): ... this. Check the funchash when pruning redundant variables. (ctf_symtypetab_sect_sizes): Adjust accordingly. * NEWS: Describe this change.
70 lines
2.4 KiB
Makefile
70 lines
2.4 KiB
Makefile
#as:
|
|
#source: data-func-1.c
|
|
#source: data-func-2.c
|
|
#objdump: --ctf
|
|
#ld: -shared -s --ctf-variables
|
|
#name: Conflicted data syms, partially indexed, stripped, with variables
|
|
|
|
.*: +file format .*
|
|
|
|
Contents of CTF section \.ctf:
|
|
|
|
Header:
|
|
Magic number: 0xdff2
|
|
Version: 4 \(CTF_VERSION_3\)
|
|
#...
|
|
Data object section: .* \(0x[1-9a-f][0-9a-f]* bytes\)
|
|
Function info section: .* \(0x[1-9a-f][0-9a-f]* bytes\)
|
|
Object index section: .* \(0xc bytes\)
|
|
Variable section: .* \(0x10 bytes\)
|
|
Type section: .* \(0x118 bytes\)
|
|
String section: .*
|
|
#...
|
|
Data objects:
|
|
bar -> 0x[0-9a-f]*: \(kind 6\) struct var_3 \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\)
|
|
var_1 -> 0x[0-9a-f]*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_666 -> 0x[0-9a-f]*: \(kind 3\) foo_t \* \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
|
|
Function objects:
|
|
func_[0-9]* -> 0x[0-9a-f]*: \(kind 5\) void \*\(\*\) \(const char \*restrict, int \(\*\)\(\*\) \(const char \*\)\) \(aligned at 0x[0-9a-f]*\)
|
|
#...
|
|
Variables:
|
|
funcs -> .*
|
|
other_func -> .*
|
|
#...
|
|
Types:
|
|
#...
|
|
.*: \(kind 6\) struct var_3 .*
|
|
#...
|
|
CTF archive member: .*/data-func-1\.c:
|
|
|
|
Header:
|
|
Magic number: 0xdff2
|
|
Version: 4 \(CTF_VERSION_3\)
|
|
#...
|
|
Parent name: \.ctf
|
|
Compilation unit name: .*/data-func-1\.c
|
|
Data object section: .* \(0x[1-9a-f][0-9a-f]* bytes\)
|
|
Type section: .* \(0xc bytes\)
|
|
String section: .*
|
|
|
|
Labels:
|
|
|
|
Data objects:
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
var_[0-9]* -> 0x80000001*: \(kind 10\) foo_t \(size 0x[0-9a-f]*\) \(aligned at 0x[0-9a-f]*\) -> .*
|
|
#...
|
|
Function objects:
|
|
|
|
Variables:
|
|
|
|
Types:
|
|
0x80000001: \(kind 10\) foo_t .* -> .* int .*
|
|
#...
|