Adjust test for PR ld/22269

Message ID 6332818.MG2PPkXIsp@polaris
State New
Headers show
Series
  • Adjust test for PR ld/22269
Related show

Commit Message

Eric Botcazou Jan. 29, 2018, 10:40 a.m.
Hi,

on the SPARC architecture, you need to pass a special flag to GAS when you're 
assembling PIC/PIE code or else you get a wrong relocation for the GOT symbol.

Tested on SPARC64/Linux (where it fixes PR22269-1), OK for mainline?

NB: it's rather confusing that run_ld_link_tests needs this tweak, but neither 
run_ld_link_exec_tests nor run_cc_link_tests does.  Maybe run_ld_link_tests 
should be fixed instead?


2018-01-29  Eric Botcazou  <ebotcazou@adacore.com>

ld/
	PR ld/22269
	* testsuite/ld-elf/shared.exp (AFLAGS_PIC): Define on SPARC.
	(pr22269-1): Pass AFLAGS_PIC to the assembler.

-- 
Eric Botcazou

Comments

Nick Clifton Jan. 29, 2018, 2:03 p.m. | #1
Hi Eric,

> on the SPARC architecture, you need to pass a special flag to GAS when you're 

> assembling PIC/PIE code or else you get a wrong relocation for the GOT symbol.

> 

> Tested on SPARC64/Linux (where it fixes PR22269-1), OK for mainline?


Approved - please apply.

> NB: it's rather confusing that run_ld_link_tests needs this tweak, but neither 

> run_ld_link_exec_tests nor run_cc_link_tests does.


Is this because they use gcc to create the assembler command line ?

> Maybe run_ld_link_tests should be fixed instead?


No.  None of those three functions has any target specific code in them, and
I would like to keep it that way.  However there might be a case for adding a
definition of ASFLAGS_PIC to ld/testsuite/config/default.exp.  Would you like
to look into that ?


> 2018-01-29  Eric Botcazou  <ebotcazou@adacore.com>

> 

> ld/

> 	PR ld/22269

> 	* testsuite/ld-elf/shared.exp (AFLAGS_PIC): Define on SPARC.

> 	(pr22269-1): Pass AFLAGS_PIC to the assembler.


Cheers
  Nick
Eric Botcazou Jan. 29, 2018, 11:28 p.m. | #2
> Approved - please apply.


Thanks, done.

> > NB: it's rather confusing that run_ld_link_tests needs this tweak, but

> > neither run_ld_link_exec_tests nor run_cc_link_tests does.

> 

> Is this because they use gcc to create the assembler command line ?


Yes, the 3 procedures can compile C files, but the last 2 pass -c to GCC while 
the first 1 passes -S and then invoke GAS manually.  The rationale for the 
discrepancy is rather unclear to me...

> No.  None of those three functions has any target specific code in them, and

> I would like to keep it that way.


I was rather thinking of making run_ld_link_tests behave like the other 2: if 
you compile a C file, invoked gcc -c , if you assemble a S file, invoke as -c.

-- 
Eric Botcazou
H.J. Lu Jan. 29, 2018, 11:32 p.m. | #3
On Mon, Jan 29, 2018 at 3:28 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> Approved - please apply.

>

> Thanks, done.

>

>> > NB: it's rather confusing that run_ld_link_tests needs this tweak, but

>> > neither run_ld_link_exec_tests nor run_cc_link_tests does.

>>

>> Is this because they use gcc to create the assembler command line ?

>

> Yes, the 3 procedures can compile C files, but the last 2 pass -c to GCC while

> the first 1 passes -S and then invoke GAS manually.  The rationale for the

> discrepancy is rather unclear to me...


GCC can be hardcoded to only use the installed assembler/linker.  It makes
-B.../ ineffective.

-- 
H.J.

Patch

diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 5c4d78aa2d..9b9cbaadfd 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -42,6 +42,10 @@  set AFLAGS_PIC ""
 if [istarget "tic6x-*-*"] {
     append AFLAGS_PIC " -mpic -mpid=near"
 }
+if [istarget "sparc*-*-*"] {
+    append AFLAGS_PIC " -K PIC"
+}
+
 # This target requires a non-default emulation for successful shared
 # library/executable builds.
 set LFLAGS ""
@@ -577,7 +581,7 @@  run_ld_link_tests [list \
 	"Build pr22269-1" \
 	"-pie -e _start --no-dynamic-linker -z text" \
 	"" \
-	"" \
+	"$AFLAGS_PIC" \
 	{ pr22269-1.c } \
 	{{readelf -rW pr22269-1.rd}} \
 	"pr22269-1" \