NetBSD Problem Report #57380
From www@netbsd.org Thu Apr 27 08:05:01 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 02E4B1A923A
for <gnats-bugs@gnats.NetBSD.org>; Thu, 27 Apr 2023 08:05:00 +0000 (UTC)
Message-Id: <20230427080459.8AC5C1A923B@mollari.NetBSD.org>
Date: Thu, 27 Apr 2023 08:04:59 +0000 (UTC)
From: rvp@SDF.ORG
Reply-To: rvp@SDF.ORG
To: gnats-bugs@NetBSD.org
Subject: ld from binutils-2.39 fails to create i386 PIEs on amd64
X-Send-Pr-Version: www-1.0
>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: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Apr 27 08:10:00 +0000 2023
>Closed-Date: Thu Apr 27 20:58:29 +0000 2023
>Last-Modified: Thu Apr 27 21:00:03 +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:/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:/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
```
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: hgutch@NetBSD.org
State-Changed-When: Thu, 27 Apr 2023 20:58:29 +0000
State-Changed-Why:
Patch applied to -current, thanks!
From: "Harold Gutch" <hgutch@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57380 CVS commit: src
Date: Thu, 27 Apr 2023 20:55:27 +0000
Module Name: src
Committed By: hgutch
Date: Thu Apr 27 20:55:27 UTC 2023
Modified Files:
src/distrib/sets/lists/comp: md.amd64
src/external/gpl3/binutils/usr.bin/ld: Makefile
Log Message:
Unbreak creation of i386 PIEs on amd64.
Functional patch by RVP; set lists updated accordingly.
This fixes PR toolchain/57380.
To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/distrib/sets/lists/comp/md.amd64
cvs rdiff -u -r1.38 -r1.39 src/external/gpl3/binutils/usr.bin/ld/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.