[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug binutils/32006] ld pulls symbols from wrong library
From: |
felix-glibc at fefe dot de |
Subject: |
[Bug binutils/32006] ld pulls symbols from wrong library |
Date: |
Tue, 23 Jul 2024 09:44:50 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=32006
Felix von Leitner <felix-glibc at fefe dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|NOTABUG |---
Status|RESOLVED |UNCONFIRMED
--- Comment #3 from Felix von Leitner <felix-glibc at fefe dot de> ---
Sorry for still pestering you about this, but let's examine the problem more
closely.
$ cat a.c
extern int a();
extern int b(); extern int b_dep();
int main() {
a();
b();
}
$ cat a_first.c
int a() { return 0; }
__asm(".section .gnu.warning.a\n.string \"a from a_first\"\n.previous");
$ cat a_second.c
int a() { return 1; }
__asm(".section .gnu.warning.a\n.string \"a from a_second\"\n.previous");
$ cat b_first.c
extern int b_dep();
int b() { return b_dep(); }
$ cat b_dep_first.c
int b_dep() { return 0; }
__asm(".section .gnu.warning.b_dep\n.string \"b_dep from
b_dep_first\"\n.previous");
$ cat b_dep_second.c
int b_dep() { return 1; }
__asm(".section .gnu.warning.b_dep\n.string \"b_dep from
b_dep_second\"\n.previous");
$ gcc -c *.c
$ ar cru first.a a_first.o b_first.o b_dep_first.o
$ ar cru second.a a_second.o b_dep_second.o
$
Remember, I want one library to reliably overrule the other one.
This setup exercises two scenarios. Scenario 1: I call a() that is in first.a
and second.a. Second, I call b() that is in first.a but calls b_dep() that is
in both libraries.
I need a way to make sure one library always wins.
I added some linker warnings so we can see which object was pulled in.
Let's see what happens:
$ gcc -o a a.c first.a second.a
a.c:(.text+0xa): warning: a from a_first
b_first.c:(.text+0xa): warning: b_dep from b_dep_first
$
Please explain that to me. You just told me to put libpthread.a AFTER libc.a so
that it overrules it.
But it gets wilder:
$ gcc -o a a.c second.a first.a
a.c:(.text+0xa): warning: a from a_second
b_first.c:(.text+0xa): warning: b_dep from b_dep_first
$
As you can see, when I switch the libraries the first one does NOT reliably
win. Now it wins if I reference the symbol from the main program, but not if
the symbol is referenced by something from inside the library.
Please advise how I can get the effect I need. I hope you don't expect me to do
preprocessor trickery to name symbols differently. The goal was to implement a
libpthread.a. That should work even if you don't have the source code for parts
of the program you are trying to link.
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug binutils/32006] New: ld pulls symbols from wrong library, felix-glibc at fefe dot de, 2024/07/22
- [Bug binutils/32006] ld pulls symbols from wrong library, hjl.tools at gmail dot com, 2024/07/22
- [Bug binutils/32006] ld pulls symbols from wrong library, amodra at gmail dot com, 2024/07/22
- [Bug binutils/32006] ld pulls symbols from wrong library,
felix-glibc at fefe dot de <=
- [Bug binutils/32006] ld pulls symbols from wrong library, address@hidden, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, jahns at dkrz dot de, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, felix-glibc at fefe dot de, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, hjl.tools at gmail dot com, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, jahns at dkrz dot de, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, jahns at dkrz dot de, 2024/07/23
- [Bug binutils/32006] ld pulls symbols from wrong library, stefan at franke dot ms, 2024/07/24
- [Bug binutils/32006] ld pulls symbols from wrong library, felics-sourceware at kettenbruch dot de, 2024/07/28