summaryrefslogtreecommitdiff
path: root/libctf/ctf-serialize.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2022-03-16 15:29:25 +0000
committerNick Alcock <nick.alcock@oracle.com>2022-03-23 13:48:32 +0000
commit203bfa2f6bd275df4089131bac0a17c278c37a1a (patch)
treecb4b22f42e78f3a9522a4e6b6f149fcc40ae933e /libctf/ctf-serialize.c
parenta12c988767e5bd6b6a15dd6ca5e3b277f5627c64 (diff)
downloadbinutils-gdb-203bfa2f6bd275df4089131bac0a17c278c37a1a.tar.gz
include, libctf, ld: extend variable section to contain functions too
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.
Diffstat (limited to 'libctf/ctf-serialize.c')
-rw-r--r--libctf/ctf-serialize.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index 89f1ac01aa1..cc9e59d4836 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -431,12 +431,12 @@ emit_symtypetab_index (ctf_dict_t *fp, ctf_dict_t *symfp, uint32_t *dp,
return 0;
}
-/* Delete data symbols that have been assigned names from the variable section.
- Must be called from within ctf_serialize, because that is the only place
- you can safely delete variables without messing up ctf_rollback. */
+/* Delete symbols that have been assigned names from the variable section. Must
+ be called from within ctf_serialize, because that is the only place you can
+ safely delete variables without messing up ctf_rollback. */
static int
-symtypetab_delete_nonstatic_vars (ctf_dict_t *fp, ctf_dict_t *symfp)
+symtypetab_delete_nonstatics (ctf_dict_t *fp, ctf_dict_t *symfp)
{
ctf_dvdef_t *dvd, *nvd;
ctf_id_t type;
@@ -445,8 +445,10 @@ symtypetab_delete_nonstatic_vars (ctf_dict_t *fp, ctf_dict_t *symfp)
{
nvd = ctf_list_next (dvd);
- if (((type = (ctf_id_t) (uintptr_t)
- ctf_dynhash_lookup (fp->ctf_objthash, dvd->dvd_name)) > 0)
+ if ((((type = (ctf_id_t) (uintptr_t)
+ ctf_dynhash_lookup (fp->ctf_objthash, dvd->dvd_name)) > 0)
+ || (type = (ctf_id_t) (uintptr_t)
+ ctf_dynhash_lookup (fp->ctf_funchash, dvd->dvd_name)) > 0)
&& ctf_dynhash_lookup (symfp->ctf_dynsyms, dvd->dvd_name) != NULL
&& type == dvd->dvd_type)
ctf_dvd_delete (fp, dvd);
@@ -560,13 +562,12 @@ ctf_symtypetab_sect_sizes (ctf_dict_t *fp, emit_symtypetab_state_t *s,
/* If we are filtering symbols out, those symbols that the linker has not
reported have now been removed from the ctf_objthash and ctf_funchash.
- Delete entries from the variable section that duplicate newly-added data
- symbols. There's no need to migrate new ones in, because the compiler
- always emits both a variable and a data symbol simultaneously, and
- filtering only happens at final link time. */
+ Delete entries from the variable section that duplicate newly-added
+ symbols. There's no need to migrate new ones in: we do that (if necessary)
+ in ctf_link_deduplicating_variables. */
if (s->filter_syms && s->symfp->ctf_dynsyms &&
- symtypetab_delete_nonstatic_vars (fp, s->symfp) < 0)
+ symtypetab_delete_nonstatics (fp, s->symfp) < 0)
return -1;
return 0;