NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
toolchain/59748: linker error when compiling -pie with -m32 and -pg
>Number: 59748
>Category: toolchain
>Synopsis: linker error when compiling -pie with -m32 and -pg
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: toolchain-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Nov 06 00:40:01 +0000 2025
>Originator: Christos Zoulas
>Release: NetBSD 11.99.3
>Organization:
Linkers R'US
>Environment:
System: NetBSD quasar.astron.com 11.99.3 NetBSD 11.99.3 (QUASAR) #62: Fri Oct 10 11:37:31 EDT 2025 christos%quasar.astron.com@localhost:/usr/src/sys/arch/amd64/compile/QUASAR amd64
Architecture: x86_64
Machine: amd64
>Description:
>How-To-Repeat:
[7:20pm] 214>cat pic.cpp
#include <iostream>
struct A {
int i;
A(int i):i(i){std::cout << "CTOR A" << std::endl;}
~A() {std::cout << "DTOR A:" << i << std::endl;}
};
struct B {
A *m_a;
B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;}
~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;}
};
int pic(void) {struct B b;return 0;}
[7:20pm] 216>cat main.cpp
#include <cstdlib>
int pic(void);
int main(void) {pic();exit(0);}
[7:21pm] 220>g++ -m32 -pg -fPIC -shared pic.cpp -o libpic.so
[7:22pm] 224>g++ -m32 -pg -fPIC -pie main.cpp -L${PWD} -Wl,-R${PWD} -lpic
ld: /usr/lib/../lib/i386/libc_p.a(__syscall.po): copy relocation against non-copyable protected symbol `__cerror' in /u/christos/pie/libpic.so
This happens because with -pg we link against libc_p.a which brings in
the needed objects from libc into libpic.so. This strangely does not
break without -m32 although amd64 does the same.
I think we should fix this and amd64 to use the proper indirect call
although this adds a few more instructions since the error path is not
usually exercised and the code is more correct this way. All other
syscalls use _SYSCALL_ERR except the hand-crafted ones so I consider
this an accident.
>Fix:
Use indirect jmp on error.
Index: i386/sys/__clone.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/__clone.S,v
retrieving revision 1.7
diff -u -p -u -r1.7 __clone.S
--- i386/sys/__clone.S 3 May 2025 19:55:32 -0000 1.7
+++ i386/sys/__clone.S 6 Nov 2025 00:18:37 -0000
@@ -94,5 +94,5 @@ ENTRY(__clone)
addl $12,%esp
5:
popl %ebp
- jmp CERROR
+ _SYSCALL_ERR
END(__clone)
Index: i386/sys/__syscall.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/__syscall.S,v
retrieving revision 1.5
diff -u -p -u -r1.5 __syscall.S
--- i386/sys/__syscall.S 23 May 2014 02:34:19 -0000 1.5
+++ i386/sys/__syscall.S 6 Nov 2025 00:18:37 -0000
@@ -52,5 +52,5 @@ ENTRY(__syscall)
jc err
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
END(__syscall)
Index: i386/sys/__vfork14.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/__vfork14.S,v
retrieving revision 1.10
diff -u -p -u -r1.10 __vfork14.S
--- i386/sys/__vfork14.S 23 May 2014 02:34:19 -0000 1.10
+++ i386/sys/__vfork14.S 6 Nov 2025 00:18:37 -0000
@@ -57,5 +57,5 @@ ENTRY(__vfork14)
jmp *%ecx
err:
pushl %ecx
- jmp CERROR
+ _SYSCALL_ERR
END(__vfork14)
Index: i386/sys/brk.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/brk.S,v
retrieving revision 1.24
diff -u -p -u -r1.24 brk.S
--- i386/sys/brk.S 23 May 2014 02:34:19 -0000 1.24
+++ i386/sys/brk.S 6 Nov 2025 00:18:37 -0000
@@ -74,7 +74,7 @@ ENTRY(_brk)
xorl %eax,%eax
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
#else
movl 4(%esp),%ecx
cmpl %ecx,_C_LABEL(__minbrk)
@@ -88,6 +88,6 @@ err:
xorl %eax,%eax
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
#endif
END(_brk)
Index: i386/sys/ptrace.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/ptrace.S,v
retrieving revision 1.20
diff -u -p -u -r1.20 ptrace.S
--- i386/sys/ptrace.S 3 May 2025 19:55:32 -0000 1.20
+++ i386/sys/ptrace.S 6 Nov 2025 00:18:37 -0000
@@ -53,5 +53,5 @@ ENTRY(ptrace)
jc err
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
END(ptrace)
Index: i386/sys/sbrk.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/sbrk.S,v
retrieving revision 1.22
diff -u -p -u -r1.22 sbrk.S
--- i386/sys/sbrk.S 23 May 2014 02:34:19 -0000 1.22
+++ i386/sys/sbrk.S 6 Nov 2025 00:18:37 -0000
@@ -73,7 +73,7 @@ ENTRY(_sbrk)
out:
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
#else
movl 4(%esp),%ecx
movl CURBRK,%eax
@@ -87,6 +87,6 @@ err:
out:
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
#endif
END(_sbrk)
Index: i386/sys/syscall.S
===================================================================
RCS file: /cvsroot/src/lib/libc/arch/i386/sys/syscall.S,v
retrieving revision 1.14
diff -u -p -u -r1.14 syscall.S
--- i386/sys/syscall.S 18 Apr 2020 23:55:50 -0000 1.14
+++ i386/sys/syscall.S 6 Nov 2025 00:18:37 -0000
@@ -50,6 +50,6 @@ ENTRY(_syscall)
jc err
ret
err:
- jmp CERROR
+ _SYSCALL_ERR
END(_syscall)
WEAK_ALIAS(syscall,_syscall)
Home |
Main Index |
Thread Index |
Old Index