Bug 21264 - Selective static linking of libm.a fails due to unresolved _dl_x86_cpu_features symbol
Summary: Selective static linking of libm.a fails due to unresolved _dl_x86_cpu_featur...
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-17 14:31 UTC by Florian Weimer
Modified: 2017-03-17 17:18 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2017-03-17 14:31:06 UTC
Example from the downstream bug report:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv)
{
        printf("string:%s\n",argv[1]);
	float input=strtof(argv[1],NULL);
	printf("input:%f\n",input);
        float result;
        result = sin(input);
        printf("%f\n",result);
	return 0;
}

GCC command line (note that libm is linked statically, but libc is linked dynamically):

gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 

Actual results:

Linker error message:

/usr/lib64/libm-2.25.90.a(s_sin.o): In function `__cos_ifunc':
(.text+0x4d22): undefined reference to `_dl_x86_cpu_features'
/usr/lib64/libm-2.25.90.a(s_sin.o): In function `__sin_ifunc':
(.text+0x4d52): undefined reference to `_dl_x86_cpu_features'

I'm not sure if it is reasonable for our users to expect this to work, but so far we did not actively prevent that from happening.
Comment 1 Carlos O'Donell 2017-03-17 16:40:45 UTC
(In reply to Florian Weimer from comment #0)
> Example from the downstream bug report:
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
> 
> int main(int argc, char **argv)
> {
>         printf("string:%s\n",argv[1]);
> 	float input=strtof(argv[1],NULL);
> 	printf("input:%f\n",input);
>         float result;
>         result = sin(input);
>         printf("%f\n",result);
> 	return 0;
> }
> 
> GCC command line (note that libm is linked statically, but libc is linked
> dynamically):
> 
> gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
> 
> Actual results:
> 
> Linker error message:
> 
> /usr/lib64/libm-2.25.90.a(s_sin.o): In function `__cos_ifunc':
> (.text+0x4d22): undefined reference to `_dl_x86_cpu_features'
> /usr/lib64/libm-2.25.90.a(s_sin.o): In function `__sin_ifunc':
> (.text+0x4d52): undefined reference to `_dl_x86_cpu_features'
> 
> I'm not sure if it is reasonable for our users to expect this to work, but
> so far we did not actively prevent that from happening.

This would mix old / new libm.a with old / new libc.so.6 / ld.so and that's not supported.

Either you link statically or you link dynamically. The entire runtime has to come together to form the basis of the implementation.

The exceptions are things like NSS modules which have some special caveats here.
Comment 2 Carlos O'Donell 2017-03-17 17:18:54 UTC
(In reply to Florian Weimer from comment #0)
> I'm not sure if it is reasonable for our users to expect this to work, but
> so far we did not actively prevent that from happening.

The presence of libm.a is an implementation detail. We might reopen this issue to discuss ways to prevent users from thinking it works to link against just libc.a instead of using -static.