Fix temp-dir leakage in per-bfd-sharing.exp

Message ID AM8PR10MB47082A50E78A5A4435F4497DE43D9@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM
State New
Headers show
Series
  • Fix temp-dir leakage in per-bfd-sharing.exp
Related show

Commit Message

Bernd Edlinger June 2, 2021, 5:30 p.m.
Whan using clang as compiler this compile step fails due to the
unknown option "-Wl,--build-id".  This leaks the already created
temp-dir.

Fixed by compiling first, and creating the temp-dir only when the
compile succeeded.

2021-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* gdb.dwarf2/per-bfd-sharing.exp: Fix temp-dir leakage.
---
 gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
1.9.1

Comments

Tom Tromey June 2, 2021, 6:23 p.m. | #1
>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:


Bernd> Whan using clang as compiler this compile step fails due to the
Bernd> unknown option "-Wl,--build-id".  This leaks the already created
Bernd> temp-dir.

How are build ids made with clang?

Bernd> Fixed by compiling first, and creating the temp-dir only when the
Bernd> compile succeeded.

Bernd> 2021-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>

Bernd> 	* gdb.dwarf2/per-bfd-sharing.exp: Fix temp-dir leakage.

Thank you, this is ok.

Tom
Bernd Edlinger June 2, 2021, 7:16 p.m. | #2
On 6/2/21 8:23 PM, Tom Tromey wrote:
>>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:

> 

> Bernd> Whan using clang as compiler this compile step fails due to the

> Bernd> unknown option "-Wl,--build-id".  This leaks the already created

> Bernd> temp-dir.

> 

> How are build ids made with clang?

> 


Sorry, unfortunately I don't know anything about clang.
Aehm, by the way, what is a build id?


Thanks
Bernd.
Bernd Edlinger June 3, 2021, 5:37 a.m. | #3
On 6/2/21 8:23 PM, Tom Tromey wrote:
>>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:

> 

> Bernd> Whan using clang as compiler this compile step fails due to the

> Bernd> unknown option "-Wl,--build-id".  This leaks the already created

> Bernd> temp-dir.

> 

> How are build ids made with clang?

> 

> Bernd> Fixed by compiling first, and creating the temp-dir only when the

> Bernd> compile succeeded.

> 

> Bernd> 2021-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>

> 

> Bernd> 	* gdb.dwarf2/per-bfd-sharing.exp: Fix temp-dir leakage.

> 

> Thank you, this is ok.

> 


Sure, what I did is this:

gdb --args gdb ./compile-cplus-anonymous
GNU gdb (GDB) 11.0.50.20210601-git
...
(gdb) r
Starting program: /home/ed/gnu/gdb-install-1/bin/gdb ./compile-cplus-anonymous
...
(gdb) b main
Haltepunkt 1 at 0x401165: file /home/ed/gnu/gdb-build-1/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.compile/compile-cplus-anonymous.cc, line 71.
(gdb) r
Starting program: /home/ed/gnu/gdb-build-1/gdb/testsuite/outputs/gdb.compile/compile-cplus-anonymous/compile-cplus-anonymous 
(gdb) compile code var = anon_e
[Detaching after fork from child process 4880]
*** WARNUNG *** es gibt aktive Plugins – bitte Fehler nur dann melden, wenn diese auch ohne alle Plugins reproduziert werden können.
Ereignis                         | Plugins
PLUGIN_PRE_GENERICIZE            | libcp1plugin
PLUGIN_GGC_MARKING               | libcp1plugin
PLUGIN_PRAGMAS                   | libcp1plugin
gdb command line: In Funktion »void _gdb_expr(__gdb_regs*)«:
gdb command line:1:1: interner Compiler-Fehler: in set_decl_context_in_fn, bei cp/name-lookup.c:3359
0x6f03a1 set_decl_context_in_fn
	../../gcc-trunk/gcc/cp/name-lookup.c:3359
0x6f03a1 do_pushdecl
	../../gcc-trunk/gcc/cp/name-lookup.c:3633
0xa99c42 do_pushdecl
	../../gcc-trunk/gcc/cp/name-lookup.c:3852
0xa99c42 pushdecl(tree_node*, bool)
	../../gcc-trunk/gcc/cp/name-lookup.c:3852
0x7ffff7fa044c safe_pushdecl
	../../gcc-trunk/libcc1/libcp1plugin.cc:654
...
0x7ffff7fa6aa1 cc1_plugin::connection::do_wait(bool)
	../../gcc-trunk/libcc1/connection.cc:135
0x7ffff7f98f1d cc1_plugin::connection::wait_for_result()
	../../gcc-trunk/libcc1/connection.hh:75
0x7ffff7f98f1d cc1_plugin::status cc1_plugin::call<int, gcc_cp_oracle_request, char const*>(cc1_plugin::connection*, char const*, int*, gcc_cp_oracle_request, char const*)
	../../gcc-trunk/libcc1/rpc.hh:116
0x7ffff7f98f1d plugin_binding_oracle
	../../gcc-trunk/libcc1/libcp1plugin.cc:101
0xa965e7 query_oracle
	../../gcc-trunk/gcc/cp/name-lookup.c:2387
Thread 1 "gdb" received signal SIGPIPE, Broken pipe.
0x00007ffff704b34d in write () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0  0x00007ffff704b34d in write () from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007ffff7e1816f in cc1_plugin::connection::send (this=<optimized out>, c=<optimized out>)
    at ../../gcc-trunk/libcc1/connection.cc:33
#2  0x00007ffff7e128c4 in cc1_plugin::invoker<int, gcc_cp_oracle_request, char const*>::invoke<(anonymous namespace)::cp_call_binding_oracle> (conn=0xee03b0) at ../../gcc-trunk/libcc1/libcp1.cc:81
#3  0x00007ffff7e183c2 in cc1_plugin::connection::do_wait (this=0xee03b0, want_result=<optimized out>)
    at ../../gcc-trunk/libcc1/connection.cc:135
#4  0x00007ffff7e1708c in cc1_plugin::connection::wait_for_query (this=<optimized out>) at ../../gcc-trunk/libcc1/connection.hh:82
#5  cc1_plugin::base_gdb_plugin<gcc_cp_context>::fork_exec (stderr_fds=0x7fffffffd778, spair_fds=0x7fffffffd770, argv=0x12fe060, 
    this=<optimized out>) at ../../gcc-trunk/libcc1/gdbctx.hh:248
#6  cc1_plugin::base_gdb_plugin<gcc_cp_context>::do_compile (s=<optimized out>, filename=<optimized out>)
    at ../../gcc-trunk/libcc1/gdbctx.hh:315
#7  0x00000000005058e4 in compile_instance::compile (this=<optimized out>, filename=<optimized out>, verbose_level=<optimized out>)
    at ../../binutils-gdb/gdb/compile/compile.c:914
#8  0x0000000000506387 in compile_to_object (scope=<optimized out>, cmd_string=<optimized out>, cmd=<optimized out>)
    at /home/ed/gnu/install/include/c++/12.0.0/bits/basic_string.h:193
#9  eval_compile_command (cmd=0x0, cmd_string=0x124bb4d "var = anon_e", scope=COMPILE_I_SIMPLE_SCOPE, scope_data=0x0)
    at ../../binutils-gdb/gdb/compile/compile.c:789
#10 0x00000000005070dc in compile_code_command (args=<optimized out>, from_tty=<optimized out>)
    at ../../binutils-gdb/gdb/compile/compile.c:341
#11 0x00000000004ddbb2 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>)
    at ../../binutils-gdb/gdb/cli/cli-decode.c:2176
#12 0x0000000000776c82 in execute_command (p=<optimized out>, p@entry=0x124bb40 "compile code var = anon_e", from_tty=1)
    at ../../binutils-gdb/gdb/top.c:674
#13 0x000000000059e8ed in command_handler (command=0x124bb40 "compile code var = anon_e") at ../../binutils-gdb/gdb/event-top.c:588
#14 0x000000000059ec0b in command_line_handler (rl=...) at ../../binutils-gdb/gdb/event-top.c:773
#15 0x000000000059f1d0 in gdb_rl_callback_handler (rl=0xcce3c0 "compile code var = anon_e")
    at ../../binutils-gdb/gdb/event-top.c:218
#16 0x00000000007f8e08 in rl_callback_read_char () at ../../../binutils-gdb/readline/readline/callback.c:281
#17 0x000000000059db2e in gdb_rl_callback_read_char_wrapper_noexcept () at ../../binutils-gdb/gdb/event-top.c:176
#18 0x000000000059f0be in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at ../../binutils-gdb/gdb/event-top.c:193
#19 0x000000000059d940 in stdin_event_handler (error=<optimized out>, client_data=0xcccd10)
    at ../../binutils-gdb/gdb/event-top.c:515
#20 0x00000000008ca836 in gdb_wait_for_event (block=block@entry=1) at ../../binutils-gdb/gdbsupport/event-loop.cc:701
#21 0x00000000008caa7d in gdb_wait_for_event (block=1) at ../../binutils-gdb/gdbsupport/event-loop.cc:597
#22 gdb_do_one_event () at ../../binutils-gdb/gdbsupport/event-loop.cc:237
#23 0x0000000000654f05 in start_event_loop () at ../../binutils-gdb/gdb/main.c:421
#24 captured_command_loop () at ../../binutils-gdb/gdb/main.c:481
#25 0x00000000006568d5 in captured_main (data=data@entry=0x7fffffffdd80) at ../../binutils-gdb/gdb/main.c:1353
#26 gdb_main (args=args@entry=0x7fffffffddb0) at ../../binutils-gdb/gdb/main.c:1368
#27 0x0000000000427b65 in main (argc=<optimized out>, argv=<optimized out>) at ../../binutils-gdb/gdb/gdb.c:32


So the plugin forks, executes gcc, and does something that
causes gcc to crash.
Now the plugin uses a pipe to send more commands to the already died
gcc, and since the write is sending data to a closed pipe, the SIGPIPE
is sent to the gdb process which dies immediately.

I believe it is right to avoid the SIGPIPE before calling the plugin,
instead of doing that in gcc-trunk, since we don't know which version
we will be calling, and all versions I tried have failed like this.


Bernd.

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp b/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
index 081088a..48a30fa 100644
--- a/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
+++ b/gdb/testsuite/gdb.dwarf2/per-bfd-sharing.exp
@@ -18,6 +18,11 @@ 
 
 standard_testfile
 
+if { [build_executable "failed to prepare" $testfile $srcfile \
+	  {debug additional_flags=-Wl,--build-id}] == -1 } {
+    return
+}
+
 lassign [remote_exec host mktemp -d] ret cache_dir
 
 # The output of mktemp contains an end of line, remove it.
@@ -30,11 +35,6 @@  if { $ret != 0 } {
 
 verbose -log "Index cache dir: $cache_dir"
 
-if { [build_executable "failed to prepare" $testfile $srcfile \
-	  {debug additional_flags=-Wl,--build-id}] == -1 } {
-    return
-}
-
 # Populate the index-cache.
 with_test_prefix "populate index cache" {
     clean_restart