From fa1c0170176a5e4820f43824cffe80ffc4e7a717 Mon Sep 17 00:00:00 2001 From: Claudiu Zissulescu Date: Fri, 8 Jul 2016 11:55:49 +0200 Subject: [PATCH] [ARC] Fix/improve small data support. The R_ARC_SDA32 is wrongly described as a ME relocation, fix it. Offset the __SDATA_BEGIN__ to take advantage of the signed 9-bit field of the load/store instructions. include/ 2016-07-08 Claudiu Zissulescu * elf/arc-reloc.def (ARC_SDA32): Don't use ME transformation. ld/ 2016-07-08 Claudiu Zissulescu * emulparams/arcelf.sh (SDATA_START_SYMBOLS): Add offset. * testsuite/ld-arc/sda-relocs.dd: New file. * testsuite/ld-arc/sda-relocs.ld: Likewise. * testsuite/ld-arc/sda-relocs.rd: Likewise. * testsuite/ld-arc/sda-relocs.s: Likewise. * testsuite/ld-arc/arc.exp: Add SDA tests. --- include/ChangeLog | 4 ++++ include/elf/arc-reloc.def | 2 +- ld/ChangeLog | 9 +++++++++ ld/emulparams/arcelf.sh | 2 +- ld/testsuite/ld-arc/arc.exp | 8 ++++++++ ld/testsuite/ld-arc/sda-relocs.dd | 23 ++++++++++++++++++++++ ld/testsuite/ld-arc/sda-relocs.ld | 20 +++++++++++++++++++ ld/testsuite/ld-arc/sda-relocs.rd | 15 +++++++++++++++ ld/testsuite/ld-arc/sda-relocs.s | 32 +++++++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-arc/sda-relocs.dd create mode 100644 ld/testsuite/ld-arc/sda-relocs.ld create mode 100644 ld/testsuite/ld-arc/sda-relocs.rd create mode 100644 ld/testsuite/ld-arc/sda-relocs.s diff --git a/include/ChangeLog b/include/ChangeLog index 7e8cd9fd227..23b8a07338f 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2016-07-14 Claudiu Zissulescu + + * elf/arc-reloc.def (ARC_SDA32): Don't use ME transformation. + 2016-07-05 Andre Vieria * include/elf/arm.h (SHF_ARM_NOREAD): Rename to ... diff --git a/include/elf/arc-reloc.def b/include/elf/arc-reloc.def index a995056840a..17c24290427 100644 --- a/include/elf/arc-reloc.def +++ b/include/elf/arc-reloc.def @@ -139,7 +139,7 @@ ARC_RELOC_HOWTO(ARC_SDA32, 18, \ 32, \ replace_word32, \ signed, \ - ( ME ( ( ( S + A ) - _SDA_BASE_ ) ) )) + ( ( ( S + A ) - _SDA_BASE_ ) )) ARC_RELOC_HOWTO(ARC_SDA_LDST, 19, \ 2, \ diff --git a/ld/ChangeLog b/ld/ChangeLog index 98de1fb325d..035db916a38 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2016-07-14 Claudiu Zissulescu + + * emulparams/arcelf.sh (SDATA_START_SYMBOLS): Add offset. + * testsuite/ld-arc/sda-relocs.dd: New file. + * testsuite/ld-arc/sda-relocs.ld: Likewise. + * testsuite/ld-arc/sda-relocs.rd: Likewise. + * testsuite/ld-arc/sda-relocs.s: Likewise. + * testsuite/ld-arc/arc.exp: Add SDA tests. + 2016-07-11 Claudiu Zissulescu * testsuite/ld-arc/nps-1b.err: Update test to handle more diff --git a/ld/emulparams/arcelf.sh b/ld/emulparams/arcelf.sh index 7777f9b8ca5..9b52e2c81d7 100644 --- a/ld/emulparams/arcelf.sh +++ b/ld/emulparams/arcelf.sh @@ -15,7 +15,7 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)" ARCH=arc MACHINE= ENTRY=__start -SDATA_START_SYMBOLS='__SDATA_BEGIN__ = .;' +SDATA_START_SYMBOLS='__SDATA_BEGIN__ = . + 0x100;' OTHER_SECTIONS="/DISCARD/ : { *(.__arc_profile_*) }" EMBEDDED=yes diff --git a/ld/testsuite/ld-arc/arc.exp b/ld/testsuite/ld-arc/arc.exp index 0cf622888fa..f8838ccb7dc 100644 --- a/ld/testsuite/ld-arc/arc.exp +++ b/ld/testsuite/ld-arc/arc.exp @@ -28,3 +28,11 @@ foreach arc_test $arc_test_list { run_dump_test [file rootname $arc_test] } +set arccommon_tests { + { "SDA relocs" + "-q -T sda-relocs.ld" "" "-mcpu=archs" {sda-relocs.s} + {{objdump -fdw sda-relocs.dd} {readelf --relocs sda-relocs.rd}} + "sda-relocs.so" } +} + +run_ld_link_tests $arccommon_tests diff --git a/ld/testsuite/ld-arc/sda-relocs.dd b/ld/testsuite/ld-arc/sda-relocs.dd new file mode 100644 index 00000000000..c4a3ff664ca --- /dev/null +++ b/ld/testsuite/ld-arc/sda-relocs.dd @@ -0,0 +1,23 @@ + +.*: file format .* +architecture: ARCv2, flags 0x00000113: +HAS_RELOC, EXEC_P, HAS_SYMS, D_PAGED +start address 0x00010000 + + +Disassembly of section .text: + +[0-9a-f]+ <__SDATA_BEGIN__>: + [0-9a-f]+: c8[0-9a-f]+ ld_s r0,\[gp,[0-9]+\] + [0-9a-f]+: cc[0-9a-f]+ ld(h|w)_s r0,\[gp,[0-9]+\] + [0-9a-f]+: ca[0-9a-f]+ ldb_s r0,\[gp,[0-9]+\] + [0-9a-f]+: 12[0-9a-f]+ 3600 ld.as r0,\[gp,[0-9]+\] + [0-9a-f]+: 1a[0-9a-f]+ 3018 st.as r0,\[gp,[0-9]+\] + [0-9a-f]+: 12[0-9a-f]+ 3000 ld r0,\[gp,[0-9]+\] + [0-9a-f]+: 12[0-9a-f]+ 3080 ldb r0,\[gp,[0-9]+\] + [0-9a-f]+: 12[0-9a-f]+ 3100 ld(h|w) r0,\[gp,[0-9]+\] + [0-9a-f]+: 1a[0-9a-f]+ 301c sth.as r0,\[gp,[0-9]+\] + [0-9a-f]+: 50[0-9a-f]+ ld_s r1,\[gp,[0-9]+\] + [0-9a-f]+: 50[0-9a-f]+ st_s r0,\[gp,[0-9]+\] + [0-9a-f]+: 2200 3f82 0000 002c add r2,gp,0x[0-9a-f]+ + [0-9a-f]+: 78e0 nop_s diff --git a/ld/testsuite/ld-arc/sda-relocs.ld b/ld/testsuite/ld-arc/sda-relocs.ld new file mode 100644 index 00000000000..80dbbb5dc10 --- /dev/null +++ b/ld/testsuite/ld-arc/sda-relocs.ld @@ -0,0 +1,20 @@ +/* Default linker script, for normal executables */ +OUTPUT_FORMAT("elf32-littlearc", "elf32-bigarc", + "elf32-littlearc") + +OUTPUT_ARCH(arc) +ENTRY(__start) + +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + PROVIDE (__start = 0x10000); + . = 0x10000 + SIZEOF_HEADERS; + + .text : {__SDATA_BEGIN__ = .; *(.text .stub .text.*)} =0 + .sdata : {*(.sdata .sdata.*)} + .sbss : {*(.sbss .sbss.*)} + + /DISCARD/ : { *(.__arc_profile_*) } + /DISCARD/ : { *(.note.GNU-stack) } +} diff --git a/ld/testsuite/ld-arc/sda-relocs.rd b/ld/testsuite/ld-arc/sda-relocs.rd new file mode 100644 index 00000000000..6a52eac7752 --- /dev/null +++ b/ld/testsuite/ld-arc/sda-relocs.rd @@ -0,0 +1,15 @@ + +Relocation section '\.rela\.text' .*: + Offset +Info +Type +Sym.Value +Sym. Name \+ Addend +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA16_LD2 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA16_LD1 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA16_LD [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST2 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST2 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA_LDST1 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA16_ST2 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA16_ST2 [0-9a-f]+ a \+ 0 +[0-9a-f]+ [0-9a-f]+ R_ARC_SDA32_ME [0-9a-f]+ a \+ 0 diff --git a/ld/testsuite/ld-arc/sda-relocs.s b/ld/testsuite/ld-arc/sda-relocs.s new file mode 100644 index 00000000000..40ff37ddb9c --- /dev/null +++ b/ld/testsuite/ld-arc/sda-relocs.s @@ -0,0 +1,32 @@ + .section .text + .align 4 +;;; all the ops should have the same offset. + ld_s r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA16_LD2 + ldh_s r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA16_LD1 + ldb_s r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA16_LD + ld.as r0,[gp,@a@sda] + st.as r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA_LDST2 + ld r0,[gp,@a@sda] + ldb r0,[gp,@a@sda] + ldh r0,[gp,@a@sda] + ;; ldd r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA_LDST + sth.as r0,[gp,@a@sda] + ;; BFD_RELOC_ARC_SDA_LDST1 + ld_s r1,[gp,@a@sda] + st_s r0,[gp,@a@sda] + ;; BFD_ARC_SDA16_ST2 + add r2, gp, @a@sda + ;; BFD_ARC_SDA32_ME + + .global a + .section .sbss,"aw",@nobits + .align 4 + .type a, @object + .size a, 4 +a: + .zero 4 -- 2.30.2