public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Vineet Gupta <vineetg@rivosinc.com>
To: libc-alpha@sourceware.org
Cc: "Carlos O'Donell" <carlos@redhat.com>,
	"Fangrui Song" <maskray@google.com>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"nelson Chu" <nelson@rivosinc.com>,
	palmer@rivosinc.com, gnu-toolchain@rivosinc.com,
	"Vineet Gupta" <vineetg@rivosinc.com>
Subject: [PATCH] Revert "Correctly determine libc.so 'OUTPUT_FORMAT' when cross-compiling."
Date: Tue, 22 Nov 2022 18:59:32 -0800	[thread overview]
Message-ID: <20221123025932.473655-1-vineetg@rivosinc.com> (raw)

This reverts commit 361d6454c034a920f2c96517c277990d390b9652.

This trips up riscv gnu toolchain builds [1]

riscv ld segfaults when linking libgcc because libc.so linker script
contains `OUTPUT_FORMAT(elf32-little)` vs. `OUTPUT_FORMAT(elf32-littleriscv)`.

This patch causes builds to lookup riscv32* prefixed objdump and failing
to find it falls back to host objdump which is the root of the issue.
The host objdump in turn generates `OUTPUT_FORMAT(elf32-little)`

riscv glibc multilib builds lack riscv32 prefix binaries. They have a
single set of "riscv64" prefixed binaries supporting both 32 and 64-bit
abis: ilp32/ilp32d/lp64/lp64d using -march/-mabi.

FWIW I'm not sure how this patch fixed a real problem to begin with.
At least for the riscv toolchain builds the non-prefixed objdump was
still from the cross-tools and behaved exactly same as the prefixed one.
At least it was not picking up the host version which would fail -
ironically what this patch ended up triggering for riscv.

| $ find TC_INSTALL -name *objdump -exec md5sum {} \;
| 5fd0b967d4977a4f8bc3a7b7a9318b1d  ./bin/riscv64-unknown-linux-gnu-objdump
| 5fd0b967d4977a4f8bc3a7b7a9318b1d  ./riscv64-unknown-linux-gnu/bin/objdump
|
| $ ./bin/riscv64-unknown-linux-gnu-objdump -f ./xx.lds.so  | grep "file format"
| ./xx.lds.so:     file format elf32-littleriscv
|
| $ ./riscv64-unknown-linux-gnu/bin/objdump -f ./xx.lds.so  | grep "file format"
| ./xx.lds.so:     file format elf32-littleriscv

[1] https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1161

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
 aclocal.m4   |  2 ++
 configure    | 96 ++--------------------------------------------------
 configure.ac |  1 -
 3 files changed, 5 insertions(+), 94 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index 531b11cb6988..3b4df4a37197 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -122,6 +122,8 @@ AS=`$CC -print-prog-name=as`
 LD=`$CC -print-prog-name=$LDNAME`
 AR=`$CC -print-prog-name=ar`
 AC_SUBST(AR)
+OBJDUMP=`$CC -print-prog-name=objdump`
+AC_SUBST(OBJDUMP)
 OBJCOPY=`$CC -print-prog-name=objcopy`
 AC_SUBST(OBJCOPY)
 GPROF=`$CC -print-prog-name=gprof`
diff --git a/configure b/configure
index cb0996d59e21..fbaa20e040b5 100755
--- a/configure
+++ b/configure
@@ -649,6 +649,7 @@ LD
 AS
 GPROF
 OBJCOPY
+OBJDUMP
 AR
 LN_S
 INSTALL_DATA
@@ -684,7 +685,6 @@ sysheaders
 ac_ct_CXX
 CXXFLAGS
 CXX
-OBJDUMP
 READELF
 CPP
 cross_compiling
@@ -2963,98 +2963,6 @@ else
   READELF="$ac_cv_prog_READELF"
 fi
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
-set dummy ${ac_tool_prefix}objdump; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_OBJDUMP+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$OBJDUMP"; then
-  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-OBJDUMP=$ac_cv_prog_OBJDUMP
-if test -n "$OBJDUMP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
-$as_echo "$OBJDUMP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-fi
-if test -z "$ac_cv_prog_OBJDUMP"; then
-  ac_ct_OBJDUMP=$OBJDUMP
-  # Extract the first word of "objdump", so it can be a program name with args.
-set dummy objdump; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$ac_ct_OBJDUMP"; then
-  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
-    ac_cv_prog_ac_ct_OBJDUMP="objdump"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
-fi
-ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
-if test -n "$ac_ct_OBJDUMP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
-$as_echo "$ac_ct_OBJDUMP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-  if test "x$ac_ct_OBJDUMP" = x; then
-    OBJDUMP="false"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    OBJDUMP=$ac_ct_OBJDUMP
-  fi
-else
-  OBJDUMP="$ac_cv_prog_OBJDUMP"
-fi
-
 
 # We need the C++ compiler only for testing.
 ac_ext=cpp
@@ -4672,6 +4580,8 @@ AS=`$CC -print-prog-name=as`
 LD=`$CC -print-prog-name=$LDNAME`
 AR=`$CC -print-prog-name=ar`
 
+OBJDUMP=`$CC -print-prog-name=objdump`
+
 OBJCOPY=`$CC -print-prog-name=objcopy`
 
 GPROF=`$CC -print-prog-name=gprof`
diff --git a/configure.ac b/configure.ac
index 20b5e8043fad..0ca4bf56ef76 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,6 @@ fi
 AC_SUBST(cross_compiling)
 AC_PROG_CPP
 AC_CHECK_TOOL(READELF, readelf, false)
-AC_CHECK_TOOL(OBJDUMP, objdump, false)
 
 # We need the C++ compiler only for testing.
 AC_PROG_CXX
-- 
2.34.1


             reply	other threads:[~2022-11-23  2:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23  2:59 Vineet Gupta [this message]
2022-11-26 14:57 ` Ludovic Courtès
2022-11-28  2:24   ` Vineet Gupta
2022-11-28 15:37     ` Ludovic Courtès
2022-11-28 19:04       ` Vineet Gupta
2022-11-28 23:25 ` Palmer Dabbelt
2022-11-30 12:39   ` Adhemerval Zanella Netto
2022-12-01  0:45     ` Vineet Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221123025932.473655-1-vineetg@rivosinc.com \
    --to=vineetg@rivosinc.com \
    --cc=carlos@redhat.com \
    --cc=gnu-toolchain@rivosinc.com \
    --cc=libc-alpha@sourceware.org \
    --cc=ludo@gnu.org \
    --cc=maskray@google.com \
    --cc=nelson@rivosinc.com \
    --cc=palmer@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).