NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/57380: ld from binutils-2.39 fails to create i386 PIEs on amd64



>Number:         57380
>Category:       toolchain
>Synopsis:       ld from binutils-2.39 fails to create i386 PIEs on amd64
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 27 08:10:00 +0000 2023
>Originator:     RVP
>Release:        NetBSD/amd64 10.99.3
>Organization:
>Environment:
NetBSD x202e.localdomain 10.99.3 NetBSD 10.99.3 (GENERIC) #0: Thu Apr 20 10:43:17 UTC 2023  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
On NetBSD-HEAD, after the switch to binutils-2.39, ld(1) is unable
to create 32-bit PIE binaries on amd64.

For example:

```
$ uname -a
NetBSD x202e.localdomain 10.99.3 NetBSD 10.99.3 (GENERIC) #0: Thu Apr 20 10:43:17 UTC 2023  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
$ echo $CFLAGS
-Wall -Wextra -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -flto -fpie -pipe
$ echo $LDFLAGS
-fuse-linker-plugin -Wl,--enable-new-dtags -Wl,-z,relro,-z,now -pie -s
$ gcc -m32 -fpie -pie -o cat /usr/src/bin/cat/cat.c
ld: cannot open linker script file ldscripts/elf_i386.xdce: No such file or directory
$ gcc -m32 $CFLAGS $LDFLAGS -o cat /usr/src/bin/cat/cat.c
ld: cannot open linker script file ldscripts/elf_i386.xdwe: No such file or directory
$ gcc -m32 $CFLAGS $LDFLAGS -Wl,-T/usr/tools/x86_64--netbsd/lib/ldscripts/elf_i386.xdwe -o cat /usr/src/bin/cat/cat.c
$ file cat
cat: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /usr/libexec/ld.elf_so, for NetBSD 10.99.3, stripped
$ ./cat -h
cat: unknown option -- h
Usage: cat [-beflnstuv] [-B bsize] [-] [file ...]
$
```

>How-To-Repeat:
As above.
>Fix:
Assuming these are all the missing files now needed (ie. newly added
in binutils-2.39):

```
$ for f in /usr/tools/x86_64--netbsd/lib/ldscripts/*
> do	test -f /usr/libdata/ldscripts/${f##*/} || echo ${f##*/}
> done
elf_i386.xdce
elf_i386.xde
elf_i386.xdwe
elf_i386.xe
elf_i386.xse
elf_i386.xswe
elf_i386.xwe
elf_iamcu.xdce
elf_iamcu.xde
elf_iamcu.xdwe
elf_iamcu.xe
elf_iamcu.xse
elf_iamcu.xswe
elf_iamcu.xwe
elf_x86_64.xdce
elf_x86_64.xde
elf_x86_64.xdwe
elf_x86_64.xe
elf_x86_64.xse
elf_x86_64.xswe
elf_x86_64.xwe
$
```

this patch may do the job?

```
diff -urN a/src/external/gpl3/binutils/usr.bin/ld/Makefile b/src/external/gpl3/binutils/usr.bin/ld/Makefile
--- a/src/external/gpl3/binutils/usr.bin/ld/Makefile	2023-01-09 14:38:14.000000000 +0000
+++ b/src/external/gpl3/binutils/usr.bin/ld/Makefile	2023-04-27 07:42:48.844469035 +0000
@@ -88,7 +88,7 @@
 .  endfor
 . endif
 . if ${BINUTILS_MACHINE_ARCH} == "x86_64"
-.  for e in xce xsce
+.  for e in xce xdce xde xdwe xe xsce xse xswe xwe
 .   if exists(ldscripts/${f}.${e})
 FILES+= ${f}.${e}
 .   endif
```



Home | Main Index | Thread Index | Old Index