[gdb/testsuite] Fix shlib compilation with target board unix/-pie/-fPIE
authorTom de Vries <tdevries@suse.de>
Wed, 16 Dec 2020 17:18:40 +0000 (18:18 +0100)
committerTom de Vries <tdevries@suse.de>
Wed, 16 Dec 2020 17:18:40 +0000 (18:18 +0100)
When running test-case gdb.base/info-shared.exp with target board
unix/-pie/-fPIE, we run into:
...
spawn -ignore SIGHUP gcc -fno-stack-protector \
  outputs/gdb.base/info-shared/info-shared-solib1.c.o \
  -fdiagnostics-color=never -fPIC -shared -Wl,-soname,info-shared-solib1.so \
  -lm -fPIE -pie -o outputs/gdb.base/info-shared/info-shared-solib1.so^M
ld: Scrt1.o: in function `_start':^M
start.S:104: undefined reference to `main'^M
collect2: error: ld returned 1 exit status^M
compiler exited with status 1
...

The intention of the -pie/-fPIE flags is to build and test PIE executables on
platforms where that is not the default.  However, the flags clash with the
flags required to build shared libraries.

Fix this by filtering out PIE-related flags out of the multilib_flags settings
in compile_shared_lib.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-16  Tom de Vries  <tdevries@suse.de>

* lib/gdb.exp (gdb_compile_shlib_1): Factor out of ...
(gdb_compile_shlib): ... here.  Filter out PIE-related flags.

gdb/testsuite/ChangeLog
gdb/testsuite/lib/gdb.exp

index 7249ae670d6450cf32877338b5860e8a21d0ad60..51d768c036595208c64f0cf59062a121e505279a 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-16  Tom de Vries  <tdevries@suse.de>
+
+       * lib/gdb.exp (gdb_compile_shlib_1): Factor out of ...
+       (gdb_compile_shlib): ... here.  Filter out PIE-related flags.
+
 2020-12-16  Luis Machado  <luis.machado@linaro.org>
 
        * gdb.arch/aarch64-tagged-pointer.c (main): Add a few more
index 2b6b4d5e207e511fa92e26adebd9943c45e9f508..e812237d67ae1d5c58a864a42df1c1c6f5fa53d9 100644 (file)
@@ -4283,7 +4283,7 @@ proc gdb_compile_pthreads {source dest type options} {
 
 # Build a shared library from SOURCES.
 
-proc gdb_compile_shlib {sources dest options} {
+proc gdb_compile_shlib_1 {sources dest options} {
     set obj_options $options
 
     set ada 0
@@ -4416,6 +4416,43 @@ proc gdb_compile_shlib {sources dest options} {
     return ""
 }
 
+# Build a shared library from SOURCES.  Ignore target boards PIE-related
+# multilib_flags.
+
+proc gdb_compile_shlib {sources dest options} {
+    global board
+
+    # Save multilib_flags.
+    set board [target_info name]
+    set save_multilib_flag [board_info $board multilib_flags]
+
+    # Ignore PIE-related setting in multilib_flags.
+    set multilib_flag ""
+    foreach op $save_multilib_flag {
+       if { $op == "-pie" || $op == "-no-pie" \
+                || $op == "-fPIE" || $op == "-fno-PIE"} {
+       } else {
+           append multilib_flag " $op"
+       }
+    }
+    unset_board_info "multilib_flags"
+    set_board_info multilib_flags "$multilib_flag"
+    set code [catch {gdb_compile_shlib_1 $sources $dest $options} result]
+
+    # Restore multilib_flags.
+    unset_board_info "multilib_flags"
+    set_board_info multilib_flags $save_multilib_flag
+
+    if {$code == 1} {
+       global errorInfo errorCode
+       return -code error -errorinfo $errorInfo -errorcode $errorCode $result
+    } elseif {$code > 1} {
+       return -code $code $result
+    }
+
+    return $result
+}
+
 # This is just like gdb_compile_shlib, above, except that it tries compiling
 # against several different thread libraries, to see which one this
 # system has.
This page took 0.037966 seconds and 4 git commands to generate.