This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Move new totalorder from libm to libc
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: "Gabriel F. T. Gomes" <gabriel at inconstante dot net dot br>
- Cc: <libc-alpha at sourceware dot org>
- Date: Mon, 16 Dec 2019 18:20:08 +0100
- Subject: Re: Move new totalorder from libm to libc
- References: <87tv62daqi.fsf@mid.deneb.enyo.de> <20191216140714.558e1313@tereshkova>
* Gabriel F. T. Gomes:
> On Sat, 14 Dec 2019, Florian Weimer wrote:
>
>>Should we define the new totalorder in libc, so that it is harder to
>>get the wrong version at run time due to underlinking?
>
> I didn't understand how underlinking could cause a wrong version to be
> selected. Isn't totalorder only provided by libm? Where would a user
> program get the old version from? I can only imagine it getting undefined
> references during link time.
If you build a shared object with -shared, you won't get an undefined
symbol error (with typical toolchains):
$ cat t.c
#include <math.h>
void *p = totalorder;
$ gcc -D_GNU_SOURCE -shared t.c
$ eu-readelf --symbols=.dynsym a.out
Symbol table [ 3] '.dynsym' contains 7 entries:
1 local symbol String table: [ 4] '.dynstr'
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UNDEF
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF _ITM_deregisterTMCloneTable
2: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF __gmon_start__
3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UNDEF totalorder
4: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF _ITM_registerTMCloneTable
5: 0000000000000000 0 FUNC WEAK DEFAULT UNDEF __cxa_finalize@GLIBC_2.2.5 (2)
6: 0000000000004020 8 OBJECT GLOBAL DEFAULT 19 p
$ eu-readelf -d a.out
Dynamic segment contains 25 entries:
Addr: 0x0000000000003e50 Offset: 0x002e50 Link to section: [ 4] '.dynstr'
Type Value
NEEDED Shared library: [libc.so.6]
INIT 0x0000000000001000
[…]
It's much harder to drop -lc from the linker command line, which is
why the symbol would still get a version if it were defined in libc.