Bug 31489 - --as-needed doesn't work with references to builtin functions
Summary: --as-needed doesn't work with references to builtin functions
Status: RESOLVED DUPLICATE of bug 31482
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.43 (HEAD)
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 31482
Blocks:
  Show dependency treegraph
 
Reported: 2024-03-14 17:30 UTC by H.J. Lu
Modified: 2024-03-14 23:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2024-03-14 17:30:11 UTC
GCC doesn't put builtin function symbol references, which are defined in
the shared C library, in the IR symbol table.  As the result, --as-needed
doesn't work with references to builtin functions:

[hjl@gnu-cfl-3 as-needed]$ cat x.c
#include <stdlib.h>

int
main()
{
  abort ();
  return 0;
}
[hjl@gnu-cfl-3 as-needed]$ cat bar.c
#include <stdlib.h>
#include <stdio.h>

void
abort (void)
{
  printf ("PASS\n");
  exit (0);
}
[hjl@gnu-cfl-3 as-needed]$ make
gcc -B./ -g -flto   -c -o x.o x.c
gcc -B./ -g -fPIC   -c -o bar.o bar.c
gcc -B./ -shared -o libbar.so bar.o
gcc -B./ -Wl,--as-needed -o x x.o libbar.so -Wl,-R,.
./x
make: *** [Makefile:12: all] Aborted (core dumped)
[hjl@gnu-cfl-3 as-needed]$
Comment 1 H.J. Lu 2024-03-14 23:20:03 UTC
Dup.

*** This bug has been marked as a duplicate of bug 31482 ***