Re: [PATCH] Fix various tests to use -no-pie linker flag when needed
Jan Vrany <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 2018-12-13 at 12:13 -0500, Simon Marchi wrote:
> On 2018-12-13 10:20, Jan Vrany wrote:
> > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> > index 5a5713b114..f25df0a772 100644
> > --- a/gdb/testsuite/lib/gdb.exp
> > +++ b/gdb/testsuite/lib/gdb.exp
> > @@ -3482,6 +3482,7 @@ set gdb_saved_set_unbuffered_mode_obj ""
> > # dynamically load libraries at runtime. For example, on Linux,
> > this adds
> > # -ldl so that the test can use dlopen.
> > # - nowarnings: Inhibit all compiler warnings.
> > +# - nopie: Prevent creation of PIE executables.
> > #
> > # And here are some of the not too obscure options understood by
> > DejaGnu that
> > # influence the compilation:
> > @@ -3603,6 +3604,18 @@ proc gdb_compile {source dest type options} {
> > set options [lreplace $options $nowarnings $nowarnings $flag]
> > }
> >
> > + # Replace the "nopie" option with the appropriate additional_flags
> > + # to disable PIE executables.
> > + set nopie [lsearch -exact $options nopie]
> > + if {$nopie != -1} {
> > + if [target_info exists gdb,nowarnings_flag] {
>
> s/nowarnings_flag/nopie_flag/
>
> > + set flag "ldflags=[target_info gdb,nopie_flag]"
> > + } else {
> > + set flag "ldflags=-no-pie"
> > + }
> > + set options [lreplace $options $nopie $nopie $flag]
> > + }
> > +
>
> With this, people who run tests against gcc 4.8 will be forced to create
> a specific board file to override the nopie_flag, whereas currently it's
> possible to do it all from the command line:
>
> $ make check TESTS="gdb.arch/amd64-disp-step.exp"
> RUNTESTFLAGS='CC_FOR_TARGET="gcc-4.8"'
>
> One way to avoid that would be to auto-detect whether the toolchain
> generates PIE executables by default. If the nopie option is requested
> but the toolchain generates non-PIE by default, we would not pass any
> additional flags. On Linux, we can generate an executable and use
> "readelf -h" to check for the type of ELF artifact generated.
>
> Another way would be to check whether the toolchain knows the -no-pie
> flag, and assume that if it doesn't, it's because it probably generates
> non-PIE by default, so we don't need to pass anything. That would break
> with toolchains that generate PIE by default but use another flag to
> disable PIE (I am not aware of any that fits in this category), but
> people would still have the possibiliy of overriding it with a board
> file.
I understand your point. Unfortunately I lack enough tcl/expect knowledge
to implement this, so either someone will have a look or it would have to
wait until I learn enough.
>
> Or maybe this just fine, and we can require the few people who test
> against gcc 4.8 to use a board file.
>
Yes, that was my idea, but having some sort of autodetection would be
indeed much nicer.
Jan