-# Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+# Copyright 2006-2016 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# This file was written by Alexandre Oliva <aoliva@redhat.com>
-if $tracelevel then {
- strace $tracelevel
- }
-set prms_id 0
-set bug_id 0
-
-# are we on a target board
-if ![isnative] then {
+if { ![isnative] || [is_remote host] || [skip_shlib_tests]} {
return
}
-if [get_compiler_info "ignored"] {
+if [get_compiler_info] {
return -1
}
return -1
}
+load_lib prelink-support.exp
+
set testfile "prelink"
set libsrcfile ${testfile}-lib.c
-set libfile ${objdir}/${subdir}/${testfile}.so
-if { [gdb_compile "${srcdir}/${subdir}/${libsrcfile}" "${libfile}" executable [list debug "additional_flags=-fpic -shared -nodefaultlibs"]] != ""} {
+set libfile [standard_output_file ${testfile}.so]
+
+# Use -soname so that the new library gets copied by build_executable_own_libs.
+
+if { [gdb_compile_shlib "${srcdir}/${subdir}/${libsrcfile}" "${libfile}" [list debug "ldflags=-Wl,-soname,[file tail ${libfile}]"]] != ""} {
# If creating the shared library fails, maybe we don't have the right tools
return -1
}
-# `--no-exec-shield' is for i386 where prelink in the exec-shield mode is
-# forced to push all the libraries tight together to fit into the first two
-# memory areas (either the ASCII Shield area or at least below the executable).
-# In this case its -R option cannot be applied and we falsely FAIL here as if
-# the system is already prelinked prelink has no choice how to randomize the
-# single new unprelinked library address without wasting the first one/two
-# memory areas. We do not care of the efficiency of loading such resulting
-# exec-shield unfriendly prelinked library.
-if {[catch "system \"prelink -qNR --no-exec-shield ${libfile}\""] != 0} {
- # Maybe we don't have prelink.
+set srcfile ${testfile}.c
+set executable ${testfile}t
+set binfile [standard_output_file ${executable}]
+set prelink_args [build_executable_own_libs ${testfile}.exp $executable $srcfile [list debug "ldflags=-Wl,${libfile},-rpath,[file dirname ${libfile}]"]]
+if {$prelink_args == ""} {
return -1
}
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}t
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${libfile}" "${binfile}" executable [list debug "additional_flags=-Wl,-rpath,${objdir}/${subdir}"]] != ""} {
- return -1;
+set test "split debug of executable"
+if [gdb_gnu_strip_debug $binfile] {
+ fail $test
+} else {
+ pass $test
+}
+
+if ![prelink_yes $prelink_args] {
+ # Maybe we don't have prelink.
+ return -1
}
set found 0
-set coredir "${objdir}/${subdir}/coredir.[getpid]"
+set coredir "[standard_output_file coredir.[getpid]]"
file mkdir $coredir
catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
if [remote_file build exists $i] {
- remote_exec build "mv $i ${objdir}/${subdir}/prelink.core"
+ remote_exec build "mv $i [standard_output_file prelink.core]"
set found 1
}
}
set names [glob -nocomplain -directory $coredir core.*]
if {[llength $names] == 1} {
set corefile [file join $coredir [lindex $names 0]]
- remote_exec build "mv $corefile ${objdir}/${subdir}/prelink.core"
+ remote_exec build "mv $corefile [standard_output_file prelink.core]"
set found 1
}
}
return 0
}
-if {[catch "system \"prelink -uN ${libfile}\""] != 0} {
- untested "${testfile}.so was not prelinked, maybe system libraries are not prelinked?"
- return 0
+# Relink $libfile to a different address.
+if ![prelink_yes $prelink_args] {
+ return -1
}
-catch "system \"prelink -qNR --no-exec-shield ${libfile}\""
# Start with a fresh gdb
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
-set test "prelink"
-global gdb_prompt
-gdb_test_multiple "core-file $objdir/$subdir/prelink.core" "$test" {
- -re "warning: \.dynamic section.*not at the expected address.*warning: difference.*caused by prelink, adjusting expectations.*$gdb_prompt $" {
- pass "$test"
- }
-}
+clean_restart $executable
-gdb_exit
+# Print the "adjusting expectations" message.
+gdb_test_no_output "set verbose on"
-return 0
+gdb_test "core-file [standard_output_file prelink.core]" "Using PIC \\(Position Independent Code\\) prelink displacement 0x\[^0\]\[0-9a-f\]* for \[^\r\n\]*[file tail ${libfile}].*" "seen displacement message"
+gdb_test "p &bssvar == bssvarp" " = 1" ".dynbss vs. .bss address shift"