This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Surprising result with ld -r
- From: Douglas B Rupp <rupp at adacore dot com>
- To: binutils at sourceware dot org
- Date: Mon, 16 Apr 2018 17:06:36 +0200
- Subject: Surprising result with ld -r
Given the attched files main.c, foo0.c, foo1.c
This is on x86_64-linux.
$ gcc -c foo0.c foo1.c main.c
$ gcc -o main1.pm foo0.o main.o
./main1.pm
foo0
However
$ gcc -o main1.pm foo0.o main.o -r -nostdlib
$ gcc -o main2.sm foo1.o main1.pm -Wl,-zmuldefs
./main2.sm
foo1
What is the rationale for -r not resolving "foo" in
$ gcc -o main1.pm foo0.o main.o -r -nostdlib
?
One would think that ld -r would resolve the global symbols it can
resolve at each step, rather than waiting for the final link to resolve
globals that are defined early.
--Douglas Rupp
AdaCore
#include <stdio.h>
void
foo ()
{
printf ("foo0 called\n");
}
#include <stdio.h>
void
foo ()
{
printf ("foo1 called\n");
}
extern void foo ();
void
main ()
{
foo ();
}