x86_64: Remove unneeded static PIE check for undefined weak diagnostic
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
https://sourceware.org/bugzilla/show_bug.cgi?id=21782 dropped an ld
diagnostic for R_X86_64_PC32 referencing an undefined weak symbol in
-pie links. Arguably keeping the diagnostic like other ports is more
correct, since statically resolving movl foo(%rip), %eax to the
link-time zero address produces a corrupted output.
It turns out that --enable-static-pie builds do not depend on the ld
behavior. GCC generates GOT indirection for weak declarations for
-fPIE/-fPIC, so what ld does with the PC-relative relocation doesn't
really matter. I confirmed the argument with a --enable-static-pie build
with trunk LLD, whose -pie mode reports an error for `.weak foo; movl
foo(%rip), %eax`
(https://sourceware.org/bugzilla/show_bug.cgi?id=21782#c6
---
sysdeps/x86_64/configure | 33 ---------------------------------
sysdeps/x86_64/configure.ac | 25 -------------------------
2 files changed, 58 deletions(-)
mode change 100644 => 100755 sysdeps/x86_64/configure
Comments
On Thu, Jul 8, 2021 at 12:51 PM Fangrui Song via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=21782 dropped an ld
> diagnostic for R_X86_64_PC32 referencing an undefined weak symbol in
> -pie links. Arguably keeping the diagnostic like other ports is more
> correct, since statically resolving movl foo(%rip), %eax to the
> link-time zero address produces a corrupted output.
>
> It turns out that --enable-static-pie builds do not depend on the ld
> behavior. GCC generates GOT indirection for weak declarations for
> -fPIE/-fPIC, so what ld does with the PC-relative relocation doesn't
> really matter. I confirmed the argument with a --enable-static-pie build
> with trunk LLD, whose -pie mode reports an error for `.weak foo; movl
> foo(%rip), %eax`
> (https://sourceware.org/bugzilla/show_bug.cgi?id=21782#c6
I agree that
https://sourceware.org/bugzilla/show_bug.cgi?id=21782
was a false alarm for static PIE. This linker check isn't necessary.
The patch is OK.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks.
--
H.J.
On Thu, Jul 8, 2021 at 1:09 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Jul 8, 2021 at 12:51 PM Fangrui Song via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=21782 dropped an ld
> > diagnostic for R_X86_64_PC32 referencing an undefined weak symbol in
> > -pie links. Arguably keeping the diagnostic like other ports is more
> > correct, since statically resolving movl foo(%rip), %eax to the
> > link-time zero address produces a corrupted output.
> >
> > It turns out that --enable-static-pie builds do not depend on the ld
> > behavior. GCC generates GOT indirection for weak declarations for
> > -fPIE/-fPIC, so what ld does with the PC-relative relocation doesn't
> > really matter. I confirmed the argument with a --enable-static-pie build
> > with trunk LLD, whose -pie mode reports an error for `.weak foo; movl
> > foo(%rip), %eax`
> > (https://sourceware.org/bugzilla/show_bug.cgi?id=21782#c6
>
> I agree that
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=21782
>
> was a false alarm for static PIE. This linker check isn't necessary.
>
> The patch is OK.
>
> Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
>
Please backlport it to release branches. Otherwise binutils 2.37 can't
build them.
Thanks.
old mode 100644
new mode 100755
@@ -107,39 +107,6 @@ if test x"$build_mathvec" = xnotset; then
build_mathvec=yes
fi
-if test "$static_pie" = yes; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker static PIE support" >&5
-$as_echo_n "checking for linker static PIE support... " >&6; }
-if ${libc_cv_ld_static_pie+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- cat > conftest.s <<\EOF
- .text
- .global _start
- .weak foo
-_start:
- leaq foo(%rip), %rax
-EOF
- libc_cv_pie_option="-Wl,-pie"
- if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -nostartfiles -nostdlib $no_ssp $libc_cv_pie_option -o conftest conftest.s 1>&5'
- { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
- test $ac_status = 0; }; }; then
- libc_cv_ld_static_pie=yes
- else
- libc_cv_ld_static_pie=no
- fi
-rm -f conftest*
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ld_static_pie" >&5
-$as_echo "$libc_cv_ld_static_pie" >&6; }
- if test "$libc_cv_ld_static_pie" != yes; then
- as_fn_error $? "linker support for static PIE needed" "$LINENO" 5
- fi
-fi
-
$as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
@@ -53,31 +53,6 @@ if test x"$build_mathvec" = xnotset; then
build_mathvec=yes
fi
-dnl Check if linker supports static PIE with the fix for
-dnl
-dnl https://sourceware.org/bugzilla/show_bug.cgi?id=21782
-dnl
-if test "$static_pie" = yes; then
- AC_CACHE_CHECK(for linker static PIE support, libc_cv_ld_static_pie, [dnl
-cat > conftest.s <<\EOF
- .text
- .global _start
- .weak foo
-_start:
- leaq foo(%rip), %rax
-EOF
- libc_cv_pie_option="-Wl,-pie"
- if AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -nostartfiles -nostdlib $no_ssp $libc_cv_pie_option -o conftest conftest.s 1>&AS_MESSAGE_LOG_FD); then
- libc_cv_ld_static_pie=yes
- else
- libc_cv_ld_static_pie=no
- fi
-rm -f conftest*])
- if test "$libc_cv_ld_static_pie" != yes; then
- AC_MSG_ERROR([linker support for static PIE needed])
- fi
-fi
-
dnl It is always possible to access static and hidden symbols in an
dnl position independent way.
AC_DEFINE(PI_STATIC_AND_HIDDEN)