Bug 50367 - -flto and -Wl,--as-needed combination removes some needed libraries
Summary: -flto and -Wl,--as-needed combination removes some needed libraries
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-12 18:24 UTC by Krisztian Kocsis
Modified: 2011-09-20 02:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Verbose linker output. (4.73 KB, text/plain)
2011-09-12 18:24 UTC, Krisztian Kocsis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Krisztian Kocsis 2011-09-12 18:24:08 UTC
Created attachment 25250 [details]
Verbose linker output.

When I try to build udev with gcc-4.6.1, the accelerometer module fails to link because of undefined references to sqrt, atan, etc. Unfortunately -lm is explicitly specified. If I remove -flto or -Wl,--as-needed, the module links successfully.

Verbose linker output is attached.
Comment 1 Matthias Klose 2011-09-19 21:14:50 UTC
$ cat test-flto.c 
#include <math.h>
#include <stdio.h>

int main()
{
        printf("%le\n", gamma(42));
        return 0;
}


$ gcc -Wl,--as-needed -flto test-flto.c -lm
/tmp/ccXjDUDX.ltrans0.ltrans.o: In function `main':
ccXjDUDX.ltrans0.o:(.text+0xd): undefined reference to `gamma'
collect2: ld returned 1 exit status

$ gcc -B/usr/lib/gold-ld/ -Wl,--as-needed -flto -o test-flto test-flto.c -lm
does work
Comment 2 Matthias Klose 2011-09-19 21:21:53 UTC
http://sourceware.org/bugzilla/show_bug.cgi?id=13201
Comment 3 Alan Modra 2011-09-20 02:07:39 UTC
Not a gcc bug.