|
From: <sv...@va...> - 2013-03-22 11:49:56
|
sewardj 2013-03-22 11:49:46 +0000 (Fri, 22 Mar 2013)
New Revision: 13331
Log:
Use -Wl,-Ttext-segment when static linking if possible to keep build-ids.
Fixes #317091. (Mark Wielaard, mj...@re...)
Modified files:
trunk/Makefile.tool.am
trunk/configure.in
trunk/coregrind/link_tool_exe_linux.in
Modified: trunk/coregrind/link_tool_exe_linux.in (+8 -13)
===================================================================
--- trunk/coregrind/link_tool_exe_linux.in 2013-03-18 22:51:57 +00:00 (rev 13330)
+++ trunk/coregrind/link_tool_exe_linux.in 2013-03-22 11:49:46 +00:00 (rev 13331)
@@ -27,24 +27,19 @@
# directly. It is only run as part of the build process, with
# carefully constrained inputs.
#
-# Linux specific complications:
+# Linux specific complication:
#
# - need to support both old GNU ld and gold: use -Ttext= to
-# set the text segment address.
+# set the text segment address if that is all we have. We really
+# need -Ttext-segment. Otherwise with GNU ld sections or notes
+# (like the build-id) don't get at the desired address. Luckily
+# -Ttext does the right thing for gold. So configure checks for
+# us and sets FLAG_T_TEXT.
#
-# - need to pass --build-id=none (that is, -Wl,--build-id=none to
-# gcc) if it accepts it, to ensure the linker doesn't add a
-# notes section which ends up at the default load address and
-# so defeats our attempts to keep that address clear for the
-# client. However, older linkers don't support this flag, so it
-# is tested for by configure.in and is shipped to us as part of
-# argv[2 ..].
-#
-#
# So: what we actually do:
#
# pass the specified command to the linker as-is, except, add
-# "-static" and "-Ttext=<argv[1]>" to it.
+# "-static" and "-Ttext[-segment]=<argv[1]>" to it.
# Previously we did this by adding these options after the first
# word of the rest of the arguments, which works in the common case
# when it's something like "gcc". But the linker invocation itself
@@ -80,7 +75,7 @@
($arch eq 'mipsisa64el')) {
$extra_args = "-static -Wl,--section-start=.MIPS.options=$ala";
} else {
- $extra_args = "-static -Wl,-Ttext=$ala";
+ $extra_args = "-static -Wl,@FLAG_T_TEXT@=$ala";
}
my $cmd = join(" ", @ARGV, $extra_args);
Modified: trunk/configure.in (+17 -8)
===================================================================
--- trunk/configure.in 2013-03-18 22:51:57 +00:00 (rev 13330)
+++ trunk/configure.in 2013-03-22 11:49:46 +00:00 (rev 13331)
@@ -1701,23 +1701,32 @@
CFLAGS=$safe_CFLAGS
-# does the linker support -Wl,--build-id=none ? Note, it's
-# important that we test indirectly via whichever C compiler
-# is selected, rather than testing /usr/bin/ld or whatever
-# directly.
+# We want to use use the -Ttext-segment option to the linker.
+# GNU (bfd) ld supports this directly. Newer GNU gold linkers
+# support it as an alias of -Ttext. Sadly GNU (bfd) ld's -Ttext
+# semantics are NOT what we want (GNU gold -Ttext is fine).
+#
+# For GNU (bfd) ld -Ttext-segment chooses the base at which ELF headers
+# will reside. -Ttext aligns just the .text section start (but not any
+# other section).
+#
+# So test for -Ttext-segment which is supported by all bfd ld versions
+# and use that if it exists. If it doesn't exist it must be an older
+# version of gold and we can fall back to using -Ttext which has the
+# right semantics.
-AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
+AC_MSG_CHECKING([if the linker accepts -Wl,-Ttext-segment])
safe_CFLAGS=$CFLAGS
-CFLAGS="-Wl,--build-id=none"
+CFLAGS="-Wl,-Ttext-segment=$valt_load_address_pri_norml"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([ ], [return 0;])],
[
- AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
+ AC_SUBST([FLAG_T_TEXT], ["-Ttext-segment"])
AC_MSG_RESULT([yes])
], [
- AC_SUBST([FLAG_NO_BUILD_ID], [""])
+ AC_SUBST([FLAG_T_TEXT], ["-Ttext"])
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
Modified: trunk/Makefile.tool.am (+3 -9)
===================================================================
--- trunk/Makefile.tool.am 2013-03-18 22:51:57 +00:00 (rev 13330)
+++ trunk/Makefile.tool.am 2013-03-22 11:49:46 +00:00 (rev 13331)
@@ -26,12 +26,8 @@
endif
-# -Wl,--build-id=none is needed when linking tools on Linux. Without this
-# flag newer ld versions (2.20 and later) create a .note.gnu.build-id at the
-# default text segment address, which of course means the resulting executable
-# is unusable. So we have to tell ld not to generate that, with --build-id=none.
TOOL_LDFLAGS_COMMON_LINUX = \
- -static -nodefaultlibs -nostartfiles -u _start @FLAG_NO_BUILD_ID@
+ -static -nodefaultlibs -nostartfiles -u _start
TOOL_LDFLAGS_COMMON_DARWIN = \
-nodefaultlibs -nostartfiles -Wl,-u,__start -Wl,-e,__start
@@ -61,12 +57,10 @@
# MIPS Linux default start symbol is __start, not _start like on x86 or amd
TOOL_LDFLAGS_MIPS32_LINUX = \
- -static -nodefaultlibs -nostartfiles -u __start @FLAG_NO_BUILD_ID@ \
- @FLAG_M32@
+ -static -nodefaultlibs -nostartfiles -u __start @FLAG_M32@
TOOL_LDFLAGS_MIPS64_LINUX = \
- -static -nodefaultlibs -nostartfiles -u __start @FLAG_NO_BUILD_ID@ \
- @FLAG_M64@
+ -static -nodefaultlibs -nostartfiles -u __start @FLAG_M64@
# On Android we must ask for non-executable stack, not sure why.
if VGCONF_PLATFORMS_INCLUDE_ARM_LINUX
|