public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb_compile_shlib: Only consider shlib= options when building executables
@ 2017-10-27 23:58 Simon Marchi
  2018-01-12  2:55 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2017-10-27 23:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mike Gulick, Simon Marchi

Trying to use gdb_compile_shlib with the shlib= option to build a shared
library that depends on another shared library does not work as of
today.  See:

  https://sourceware.org/ml/gdb-patches/2017-10/msg00733.html

The problem is that building the lib is done in two steps, compilation
(.c -> .o) and linking (.o -> .so) and the shlib= options are passed to
both steps.  When compiling the object file (.o), it results in gcc
complaining:

  gcc: warning: .../solib-vanish-lib2.so: linker input file unused because linking not done

The first solution I came up with was to filter the options inside
gdb_compile_shlib to remove the shlib= options from the options we pass
when compiling the .o file.  I then thought it would be simpler to
ignore the shlib= options in gdb_compile when not building an executable
(which includes shared libraries).  For other compilation types (object
file, preprocess and generate assembly), it doesn't make sense to add
shared libraries to the source file list.

Regtested on the buildbot.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_compile): Ignore shlib= and shlib_load
	options when not creating an executable.
---
 gdb/testsuite/lib/gdb.exp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 548cb06..19a286b 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3506,7 +3506,8 @@ proc gdb_compile {source dest type options} {
     set shlib_found 0
     set shlib_load 0
     foreach opt $options {
-        if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
+        if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
+	    && $type == "executable"} {
             if [test_compiler_info "xlc-*"] {
 		# IBM xlc compiler doesn't accept shared library named other
 		# than .so: use "-Wl," to bypass this
@@ -3532,7 +3533,7 @@ proc gdb_compile {source dest type options} {
 		    lappend new_options "early_flags=-Wl,--no-as-needed"
 		}
             }
-	} elseif { $opt == "shlib_load" } {
+	} elseif { $opt == "shlib_load" && $type == "executable" } {
 	    set shlib_load 1
         } else {
             lappend new_options $opt
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb_compile_shlib: Only consider shlib= options when building executables
  2017-10-27 23:58 [PATCH] gdb_compile_shlib: Only consider shlib= options when building executables Simon Marchi
@ 2018-01-12  2:55 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2018-01-12  2:55 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, Mike Gulick

On 2017-10-27 19:58, Simon Marchi wrote:
> Trying to use gdb_compile_shlib with the shlib= option to build a 
> shared
> library that depends on another shared library does not work as of
> today.  See:
> 
>   https://sourceware.org/ml/gdb-patches/2017-10/msg00733.html
> 
> The problem is that building the lib is done in two steps, compilation
> (.c -> .o) and linking (.o -> .so) and the shlib= options are passed to
> both steps.  When compiling the object file (.o), it results in gcc
> complaining:
> 
>   gcc: warning: .../solib-vanish-lib2.so: linker input file unused
> because linking not done
> 
> The first solution I came up with was to filter the options inside
> gdb_compile_shlib to remove the shlib= options from the options we pass
> when compiling the .o file.  I then thought it would be simpler to
> ignore the shlib= options in gdb_compile when not building an 
> executable
> (which includes shared libraries).  For other compilation types (object
> file, preprocess and generate assembly), it doesn't make sense to add
> shared libraries to the source file list.
> 
> Regtested on the buildbot.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (gdb_compile): Ignore shlib= and shlib_load
> 	options when not creating an executable.
> ---
>  gdb/testsuite/lib/gdb.exp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 548cb06..19a286b 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3506,7 +3506,8 @@ proc gdb_compile {source dest type options} {
>      set shlib_found 0
>      set shlib_load 0
>      foreach opt $options {
> -        if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] {
> +        if {[regexp {^shlib=(.*)} $opt dummy_var shlib_name]
> +	    && $type == "executable"} {
>              if [test_compiler_info "xlc-*"] {
>  		# IBM xlc compiler doesn't accept shared library named other
>  		# than .so: use "-Wl," to bypass this
> @@ -3532,7 +3533,7 @@ proc gdb_compile {source dest type options} {
>  		    lappend new_options "early_flags=-Wl,--no-as-needed"
>  		}
>              }
> -	} elseif { $opt == "shlib_load" } {
> +	} elseif { $opt == "shlib_load" && $type == "executable" } {
>  	    set shlib_load 1
>          } else {
>              lappend new_options $opt

I pushed this patch.

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-12  2:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27 23:58 [PATCH] gdb_compile_shlib: Only consider shlib= options when building executables Simon Marchi
2018-01-12  2:55 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).