Bug 1433347 - glibc: Selective static linking of libm.a fails due to unresolved _dl_x86_cpu_features symbol
Summary: glibc: Selective static linking of libm.a fails due to unresolved _dl_x86_cpu...
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: glibc
Version: 7.3
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: glibc team
QA Contact: qe-baseos-tools
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-03-17 12:46 UTC by Piyush Bhoot
Modified: 2017-10-31 15:36 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-06-22 18:40:07 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Sourceware 21264 None None None 2017-03-17 14:32:36 UTC

Description Piyush Bhoot 2017-03-17 12:46:04 UTC
Description of problem:

In RHEL 7.3 libm fails to link statically 
Demo program provided

Version-Release number of selected component (if applicable):
glibc-static-2.17-157.el7.x86_64
glibc-devel-2.17-157.el7.x86_64
glibc-2.17-157.el7.x86_64

How reproducible:
Always

Steps to Reproduce:
1.

#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;
}


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

Actual results:

>gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In function `__cos':
>gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In function `__cos':
(.text+0x4682): undefined reference to `_dl_x86_cpu_features'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In function `__sin':
(.text+0x46b2): undefined reference to `_dl_x86_cpu_features'
collect2: error: ld returned 1 exit status


Expected results:
No error


Additional info:


 RHEL 7.2: works
 RHEL 7.3: does not work

Comment 2 Florian Weimer 2017-03-17 14:32:37 UTC
This is an upstream issue which we incorporated with x86_64-specific math library backports.

Note that static linking is unsupported on Red Hat Enterprise Linux (as glibc-static is in the Optional channels).

Comment 3 Carlos O'Donell 2017-03-17 16:39:22 UTC
(In reply to Piyush Bhoot from comment #0)
> Description of problem:
> 
> In RHEL 7.3 libm fails to link statically 
> Demo program provided
> 
> Version-Release number of selected component (if applicable):
> glibc-static-2.17-157.el7.x86_64
> glibc-devel-2.17-157.el7.x86_64
> glibc-2.17-157.el7.x86_64
> 
> How reproducible:
> Always
> 
> Steps to Reproduce:
> 1.
> 
> #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;
> }
> 
> 
> 2.  gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
> 
> Actual results:
> 
> >gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
> /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In
> function `__cos':
> >gcc test.c -Wl,-Bstatic -lm -Wl,-Bdynamic -lc 
> /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In
> function `__cos':
> (.text+0x4682): undefined reference to `_dl_x86_cpu_features'
> /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libm.a(s_sin.o): In
> function `__sin':
> (.text+0x46b2): undefined reference to `_dl_x86_cpu_features'
> collect2: error: ld returned 1 exit status

This is not supported.

You would be mixing a static libm.a with future libc.so.6 and ld.so and that breaks the interdependencies between the core libraries which form "the implemetnation of the C runtime."

Either the entire implementation of the runtime is statically linked or none of it is statically linked. You can't choose to link parts of it statically and not others because each part depends on the other to form a complete implementation. The math library is not a thin you can link against statically, it happens we have a libm.a, but that's an implementation detail.

Please use '-static' for the entire application.

What use case do you have for this?


Note You need to log in before you can comment on or make changes to this bug.