qemu-trivial
[Top][All Lists]
Advanced

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

[Qemu-trivial] [PATCH v3] Fix linking relocatable objects on Sparc


From: James Clarke
Subject: [Qemu-trivial] [PATCH v3] Fix linking relocatable objects on Sparc
Date: Mon, 6 Jun 2016 12:12:24 +0100
User-agent: Mutt/1.6.1 (2016-04-27)

On Sparc, gcc implicitly passes --relax to the linker, but -r is
incompatible with this. Therefore, if --no-relax is supported, it should
be passed to the linker.

Signed-off-by: James Clarke <address@hidden>
---
Hi Peter,
Sorry about that, I wasn't building in a git repository, so werror was
set to no (I was unaware of the configure script doing so). I have now
tested it with werror enabled, and it works (and could reproduce the
error with the previous version).

I reworked the test slightly to mirror what the Makefile rules actually
do, as trying to combine the compilation and ld -r steps doesn't work
when CLFAGS contains -pie, which was leading to x86_64 believing that
--no-relax was not a valid option.

I also accidentally included a whitespace change in v2; sorry for the
noise.

Regards,
James

 configure | 21 +++++++++++++++++++++
 rules.mak |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index b5aab72..70237b0 100755
--- a/configure
+++ b/configure
@@ -31,6 +31,7 @@ TMPCXX="${TMPDIR1}/${TMPB}.cxx"
 TMPL="${TMPDIR1}/${TMPB}.lo"
 TMPA="${TMPDIR1}/lib${TMPB}.la"
 TMPE="${TMPDIR1}/${TMPB}.exe"
+TMPMO="${TMPDIR1}/${TMPB}.mo"
 
 rm -f config.log
 
@@ -4526,6 +4527,25 @@ if compile_prog "" "" ; then
     have_fsxattr=yes
 fi
 
+#################################################
+# Sparc implicitly links with --relax, which is
+# incompatible with -r, so --no-relax should be
+# given. It does no harm to give it on other
+# platforms too.
+
+# Note: the prototype is needed since QEMU_CFLAGS
+#       contains -Wmissing-prototypes
+cat > $TMPC << EOF
+extern int foo(void);
+int foo(void) { return 0; }
+EOF
+if ! compile_object ""; then
+  error_exit "Failed to compile object file for LD_REL_FLAGS test"
+fi
+if do_cc -nostdlib -Wl,-r -Wl,--no-relax -o $TMPMO $TMPO; then
+  LD_REL_FLAGS="-Wl,--no-relax"
+fi
+
 ##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -5529,6 +5549,7 @@ else
 fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
+echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
 echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index 4a8f464..dca5718 100644
--- a/rules.mak
+++ b/rules.mak
@@ -95,7 +95,7 @@ module-common.o: CFLAGS += $(DSO_OBJ_CFLAGS)
        $(if $(findstring /,$@),$(call quiet-command,cp $@ $(subst /,-,$@), "  
CP    $(subst /,-,$@)"))
 
 
-LD_REL := $(CC) -nostdlib -Wl,-r
+LD_REL := $(CC) -nostdlib -Wl,-r $(LD_REL_FLAGS)
 
 %.mo:
        $(call quiet-command,$(LD_REL) -o $@ $^,"  LD -r $(TARGET_DIR)$@")
-- 
2.8.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]