Re: [PATCH][PR build/24805] Explicitly export symbols from gdb_proc_service

Norbert Lange
2020-01-06T23:39:36Z

Am Mo., 6. Jan. 2020 um 20:21 Uhr schrieb Pedro Alves <palves@redhat.com>:
>
> On 1/4/20 8:20 PM, Norbert Lange wrote:
> > Compiling GDB with '-fvisibility=hidden' will remove the
> > symbols that should be exported.
> > This patch explicitly marks them as visible.
>
> Curious. We have gdb/proc-service.list supposedly for this,
> doesn't -Wl,--dynamic-list work with -fvisibility=hidden then?
>
> Thanks,
> Pedro Alves
>

Obviously it doesn't, else I would not have spent time figuring out
why libthread_db wont load.

Unfortunately you need to pass the correct visibility to the
compilation, a hidden symbol can
be optimized globally almost like a static function locally.
A visible symbol needs to be accessed though a layer of indirection.
Wish you could disable
that logic for micro controllers where that means you don't get simple
relative jumps.
Would love if the linker would be the only one controlling the type of symbol,
that would make some subset of LTO required. But thats offtopic.

-Wl,--dynamic-list merely filters the visible symbols, it does not see
"hidden" ones.

While we are at it, I see alot stuff exported from gdb, besides the
proc_service.
I am not sure where they come from or intentional

# debian gdb
# nm -D '/usr/bin/gdb' | grep ' [TVB] '
0000000000491170 T _obstack_allocated_p
0000000000491040 T _obstack_begin
0000000000491060 T _obstack_begin_1
00000000004911b0 T _obstack_free
0000000000491220 T _obstack_memory_used
0000000000491080 T _obstack_newchunk
00000000002daf80 T ps_getpid
00000000000f4f10 T ps_get_thread_area
00000000002daea0 T ps_lgetfpregs
00000000002dadc0 T ps_lgetregs
00000000002daf10 T ps_lsetfpregs
00000000002dae30 T ps_lsetregs
00000000002dada0 T ps_pdread
00000000002dadb0 T ps_pdwrite
00000000002dace0 T ps_pglobal_lookup
0000000000163770 T xmalloc
00000000001637a0 T xrealloc
0000000000167790 T _Znam
00000000001677a0 T _ZnamRKSt9nothrow_t
0000000000167720 T _Znwm
0000000000167770 T _ZnwmRKSt9nothrow_t

# gdb master built with -fvisibility=hidden
nm -D '/tmp/devsupport_gdb/usr/local/bin/gdb' | grep ' [TVB] '
0000000000a7e1a0 B __environ
0000000000a7e1a0 V environ
0000000000a7e1a8 B optarg
0000000000a7e1c8 B optind
00000000005e4f40 T ps_getpid
00000000007913c0 T ps_get_thread_area
00000000005e4fc0 T ps_lgetfpregs
00000000005e50a0 T ps_lgetregs
00000000005e4f50 T ps_lsetfpregs
00000000005e5030 T ps_lsetregs
00000000005e5120 T ps_pdread
00000000005e5110 T ps_pdwrite
00000000005e5130 T ps_pglobal_lookup
0000000000a7e1c0 B stderr
0000000000a7e1b0 B stdin
0000000000a7e180 B stdout
0000000000695510 T _Znam
0000000000691530 T _ZnamRKSt9nothrow_t
0000000000693ae0 T _Znwm
0000000000691550 T _ZnwmRKSt9nothrow_t
0000000000a6e040 V _ZTIN10__cxxabiv115__forced_unwindE
0000000000a6e1a8 V _ZTINSt13__future_base12_Result_baseE
0000000000a6dfc0 V _ZTINSt6thread6_StateE
0000000000a6dfd0 V _ZTISt12future_error
0000000000a6e0a0 V _ZTISt9bad_alloc
0000000000a6dfe8 V _ZTVN10__cxxabiv117__class_type_infoE
0000000000a6e050 V _ZTVN10__cxxabiv119__pointer_type_infoE
0000000000a6e110 V _ZTVN10__cxxabiv120__function_type_infoE
0000000000a6e0b8 V _ZTVN10__cxxabiv120__si_class_type_infoE
0000000000a6e150 V _ZTVN10__cxxabiv121__vmi_class_type_infoE
0000000000a6e1c0 V _ZTVSt12future_error