Define DIFF_EXPR_OK for avr target to allow PC relative difference relocation.
authorDenis Chertykov <chertykov@gmail.com>
Wed, 8 Jul 2015 18:35:19 +0000 (21:35 +0300)
committerDenis Chertykov <chertykov@gmail.com>
Wed, 8 Jul 2015 18:41:52 +0000 (21:41 +0300)
When generating relocation (tc_gen_reloc) 32 bit relocation fixup
is changed to new 32 bit PC relative relocation if the fixup has pc-relative
flag set.

bfd/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * elf32-avr.c: Add 32 bit PC relative relocation for AVR target.

gas/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * config/tc-avr.c (tc_gen_reloc): Change 32 bit relocation to
    32 bit PC relative and update offset if the fixup is pc-relative.
    * config/tc-avr.h (DIFF_EXPR_OK): Define to enable PC relative diff
    relocs.

gas/testsuite/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * gas/avr/pc-relative-reloc.d: New test for 32 bit pc relative reloc.
    * gas/avr/per-function-debugline.s: New test source.

include/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * elf/avr.h: Add new 32 bit PC relative relocation.

ld/testsuite/ChangeLog

2015-07-06  Pitchumani Sivanupandi <pitchumani.s@atmel.com>

    * ld-avr/gc-section-debugline.d: New test.
    * ld-avr/per-function-debugline.s: Source for new test.

13 files changed:
bfd/ChangeLog
bfd/elf32-avr.c
gas/ChangeLog
gas/config/tc-avr.c
gas/config/tc-avr.h
gas/testsuite/ChangeLog
gas/testsuite/gas/avr/pc-relative-reloc.d [new file with mode: 0644]
gas/testsuite/gas/avr/per-function-debugline.s [new file with mode: 0644]
include/ChangeLog
include/elf/avr.h
ld/testsuite/ChangeLog
ld/testsuite/ld-avr/gc-section-debugline.d [new file with mode: 0644]
ld/testsuite/ld-avr/per-function-debugline.s [new file with mode: 0644]

index 97d3ea3781ad352889468007273d97886f6b0297..e6d1783580bb252494fb2b4bb47d1bba96b85c18 100644 (file)
@@ -1,3 +1,7 @@
+2015-07-08  Pitchumani Sivanupandi <pitchumani.s@atmel.com>
+
+       * elf32-avr.c: Add 32 bit PC relative relocation for AVR target.
+
 2015-07-05  Richard Sandiford  <richard.sandiford@arm.com>
 
        * elf64-ppc.c (toc_adjusting_stub_needed): Use the symbol value
index 8651f49c3f20ca4ba37059131d3b988bbedcce1c..bd57ab79a0e80e6ae89feee1f6bb1e631cdc20c9 100644 (file)
@@ -641,7 +641,22 @@ static reloc_howto_type elf_avr_howto_table[] =
         FALSE,                 /* partial_inplace */
         0xffffff,              /* src_mask */
         0xffffff,              /* dst_mask */
-        FALSE)                 /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
+
+  /* A 32 bit PC relative relocation.  */
+  HOWTO (R_AVR_32_PCREL,       /* type */
+        0,                             /* rightshift */
+        2,                             /* size (0 = byte, 1 = short, 2 = long) */
+        32,                    /* bitsize */
+        TRUE,                  /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_bitfield, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_AVR_32_PCREL",      /* name */
+        FALSE,                 /* partial_inplace */
+        0xffffffff,    /* src_mask */
+        0xffffffff,    /* dst_mask */
+        TRUE),                 /* pcrel_offset */
 };
 
 /* Map BFD reloc types to AVR ELF reloc types.  */
@@ -689,7 +704,8 @@ static const struct avr_reloc_map avr_reloc_map[] =
   { BFD_RELOC_AVR_DIFF32,           R_AVR_DIFF32 },
   { BFD_RELOC_AVR_LDS_STS_16,       R_AVR_LDS_STS_16},
   { BFD_RELOC_AVR_PORT6,            R_AVR_PORT6},
-  { BFD_RELOC_AVR_PORT5,            R_AVR_PORT5}
+  { BFD_RELOC_AVR_PORT5,            R_AVR_PORT5},
+  { BFD_RELOC_32_PCREL,             R_AVR_32_PCREL}
 };
 
 /* Meant to be filled one day with the wrap around address for the
index f9d4892f94882ad5e45fa5e814d5593352635ed3..4439de5532dfd80817e6ae669b4d268a841a0c85 100644 (file)
@@ -1,3 +1,10 @@
+2015-07-08  Pitchumani Sivanupandi <pitchumani.s@atmel.com>
+
+       * config/tc-avr.c (tc_gen_reloc): Change 32 bit relocation to
+       32 bit PC relative and update offset if the fixup is pc-relative.
+       * config/tc-avr.h (DIFF_EXPR_OK): Define to enable PC relative diff
+       relocs.
+
 2015-07-03  Alan Modra  <amodra@gmail.com>
 
        * config/tc-ppc.c (md_show_usage): Add -m821, -m850, -m860.
index 5c8982c212c204c4aa99f81f36f42509e74af410..c69a91c98577def29a7d3f8c21c2c792c69510fe 100644 (file)
@@ -1618,6 +1618,7 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
              fixS *fixp)
 {
   arelent *reloc;
+  bfd_reloc_code_real_type code = fixp->fx_r_type;
 
   if (fixp->fx_subsy != NULL)
     {
@@ -1631,7 +1632,21 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
 
   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
-  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
+
+  if ((fixp->fx_r_type == BFD_RELOC_32) && (fixp->fx_pcrel))
+    {
+      if (seg->use_rela_p)
+        fixp->fx_offset -= md_pcrel_from_section (fixp, seg);
+      else
+        fixp->fx_offset = reloc->address;
+
+      code = BFD_RELOC_32_PCREL;
+    }
+
+  reloc->addend = fixp->fx_offset;
+
+  reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
+
   if (reloc->howto == (reloc_howto_type *) NULL)
     {
       as_bad_where (fixp->fx_file, fixp->fx_line,
@@ -1644,7 +1659,6 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
       || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
     reloc->address = fixp->fx_offset;
 
-  reloc->addend = fixp->fx_offset;
 
   return reloc;
 }
index 21471c8bb3874254efa6de038beece9b538fcea9..5501ef053f8226762f3c9af79504996332b7a17b 100644 (file)
@@ -45,6 +45,8 @@
    nonstandard escape sequences in a string.  */
 #define ONLY_STANDARD_ESCAPES
 
+#define DIFF_EXPR_OK    /* .-foo gets turned into PC relative relocs */
+
 /* GAS will call this function for any expression that can not be
    recognized.  When the function is called, `input_line_pointer'
    will point to the start of the expression.  */
index a045c852065994777a5df5dd12c320c360d13ccb..aecbef669c38cc41b995159435f3b2b6aa7ec32c 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-08  Pitchumani Sivanupandi <pitchumani.s@atmel.com>
+
+       * gas/avr/pc-relative-reloc.d: New test for 32 bit pc relative reloc.
+       * gas/avr/per-function-debugline.s: New test source.
+
 2015-07-03  Alan Modra  <alan@squeak.grove.modra.org>
 
        * gas/ppc/titan.d: Correct mfmcsrr0 disassembly.
diff --git a/gas/testsuite/gas/avr/pc-relative-reloc.d b/gas/testsuite/gas/avr/pc-relative-reloc.d
new file mode 100644 (file)
index 0000000..cc22b0b
--- /dev/null
@@ -0,0 +1,19 @@
+#name: 32 bit PC relative reloc
+#as: -mmcu=avr51 -gdwarf-sections -g
+#objdump: -r
+#source: per-function-debugline.s
+#target: avr-*-*
+
+.*:     file format elf32-avr
+
+RELOCATION RECORDS FOR \[.text.main\]:
+#...
+
+
+RELOCATION RECORDS FOR \[.debug_line\]:
+OFFSET   TYPE              VALUE 
+00000000 R_AVR_32_PCREL    .debug_line_end-0x00000004
+
+
+RELOCATION RECORDS FOR \[.debug_line.text.main\]:
+#...
diff --git a/gas/testsuite/gas/avr/per-function-debugline.s b/gas/testsuite/gas/avr/per-function-debugline.s
new file mode 100644 (file)
index 0000000..4db56e5
--- /dev/null
@@ -0,0 +1,35 @@
+       .file   "per-function-debugline.s"
+__SP_H__ = 0x3e
+__SP_L__ = 0x3d
+__SREG__ = 0x3f
+__RAMPZ__ = 0x3b
+__tmp_reg__ = 0
+__zero_reg__ = 1
+       .comm   g,2,1
+       .section        .text.main,"ax",@progbits
+.global        main
+       .type   main, @function
+main:
+       push r28
+       push r29
+       in r28,__SP_L__
+       in r29,__SP_H__
+/* prologue: function */
+/* frame size = 0 */
+/* stack size = 2 */
+.L__stack_usage = 2
+       call foo
+       lds r24,g
+       lds r25,g+1
+       sbiw r24,1
+       sts g+1,r25
+       sts g,r24
+       lds r24,g
+       lds r25,g+1
+/* epilogue start */
+       pop r29
+       pop r28
+       ret
+       .size   main, .-main
+       .ident  "GCC: (GNU) 6.0.0 20150630 (experimental)"
+.global __do_clear_bss
index d85a1b0e73cc6314c69e58b52008caecbf928186..015e304f7e99bd112686d47cf520720a026f784a 100644 (file)
@@ -1,3 +1,7 @@
+2015-07-08  Pitchumani Sivanupandi <pitchumani.s@atmel.com>
+
+       * elf/avr.h: Add new 32 bit PC relative relocation.
+
 2015-06-26  Matthew Fortune  <matthew.fortune@imgtec.com>
 
        * elf/mips.h (DT_MIPS_RLD_MAP_REL): New macro.
index 115296da404d034d0626ebe57ac2631a6849d239..f0ef47927ad80fea4c29fa111f7a89347818178c 100644 (file)
@@ -87,6 +87,7 @@ START_RELOC_NUMBERS (elf_avr_reloc_type)
      RELOC_NUMBER (R_AVR_LDS_STS_16,           33)
      RELOC_NUMBER (R_AVR_PORT6,                34)
      RELOC_NUMBER (R_AVR_PORT5,                35)
+     RELOC_NUMBER (R_AVR_32_PCREL,             36)
 END_RELOC_NUMBERS (R_AVR_max)
 
 #endif /* _ELF_AVR_H */
index 1ee6aa1e0a61dd75332efbb80f4badb3ce9d277d..9bf1e5b42ba458be6c60d0d4d8efd02d81b61ff8 100644 (file)
@@ -1,3 +1,8 @@
+2015-07-08  Pitchumani Sivanupandi <pitchumani.s@atmel.com>
+
+       * ld-avr/gc-section-debugline.d: New test.
+       * ld-avr/per-function-debugline.s: Source for new test.
+
 2015-07-05  Richard Sandiford  <richard.sandiford@arm.com>
 
        * ld-powerpc/tocopt6-inc.s, ld-powerpc/tocopt6a.s,
diff --git a/ld/testsuite/ld-avr/gc-section-debugline.d b/ld/testsuite/ld-avr/gc-section-debugline.d
new file mode 100644 (file)
index 0000000..e98ff6c
--- /dev/null
@@ -0,0 +1,70 @@
+#name: dwarf decoded line after gc-sections
+#as: -mmcu=avr51 -gdwarf-sections -g
+#ld: -mavr51 -gc-sections -u main
+#objdump: --dwarf=decodedline
+#source: per-function-debugline.s
+#target: avr-*-*
+
+.*:     file format elf32-avr
+
+Decoded dump of debug contents of section .debug_line:
+
+CU: .*:
+File name                            Line number    Starting address
+per-function-debugline.s                      39                   0
+
+per-function-debugline.s                      40                 0x2
+
+per-function-debugline.s                      41                 0x4
+
+per-function-debugline.s                      42                 0x6
+
+per-function-debugline.s                      47                 0x8
+
+per-function-debugline.s                      48                 0xc
+
+per-function-debugline.s                      49                0x10
+
+per-function-debugline.s                      50                0x12
+
+per-function-debugline.s                      51                0x16
+
+per-function-debugline.s                      52                0x1a
+
+per-function-debugline.s                      54                0x1c
+
+per-function-debugline.s                      55                0x1e
+
+per-function-debugline.s                      56                0x20
+
+per-function-debugline.s                      62                0x22
+
+per-function-debugline.s                      63                0x24
+
+per-function-debugline.s                      64                0x26
+
+per-function-debugline.s                      65                0x28
+
+per-function-debugline.s                      70                0x2a
+
+per-function-debugline.s                      71                0x2e
+
+per-function-debugline.s                      72                0x32
+
+per-function-debugline.s                      73                0x36
+
+per-function-debugline.s                      74                0x38
+
+per-function-debugline.s                      75                0x3c
+
+per-function-debugline.s                      76                0x40
+
+per-function-debugline.s                      77                0x44
+
+per-function-debugline.s                      79                0x48
+
+per-function-debugline.s                      80                0x4a
+
+per-function-debugline.s                      81                0x4c
+
+
diff --git a/ld/testsuite/ld-avr/per-function-debugline.s b/ld/testsuite/ld-avr/per-function-debugline.s
new file mode 100644 (file)
index 0000000..361cb00
--- /dev/null
@@ -0,0 +1,84 @@
+       .file   "per-function-debugline.s"
+__SP_H__ = 0x3e
+__SP_L__ = 0x3d
+__SREG__ = 0x3f
+__RAMPZ__ = 0x3b
+__tmp_reg__ = 0
+__zero_reg__ = 1
+       .comm   g,2,1
+       .section        .text.bar,"ax",@progbits
+.global        bar
+       .type   bar, @function
+bar:
+       push r28
+       push r29
+       rcall .
+       in r28,__SP_L__
+       in r29,__SP_H__
+/* prologue: function */
+/* frame size = 2 */
+/* stack size = 4 */
+.L__stack_usage = 4
+       ldd r24,Y+1
+       ldd r25,Y+2
+       adiw r24,1
+       std Y+2,r25
+       std Y+1,r24
+       nop
+/* epilogue start */
+       pop __tmp_reg__
+       pop __tmp_reg__
+       pop r29
+       pop r28
+       ret
+       .size   bar, .-bar
+       .section        .text.foo,"ax",@progbits
+.global        foo
+       .type   foo, @function
+foo:
+       push r28
+       push r29
+       in r28,__SP_L__
+       in r29,__SP_H__
+/* prologue: function */
+/* frame size = 0 */
+/* stack size = 2 */
+.L__stack_usage = 2
+       lds r24,g
+       lds r25,g+1
+       adiw r24,1
+       sts g+1,r25
+       sts g,r24
+       nop
+/* epilogue start */
+       pop r29
+       pop r28
+       ret
+       .size   foo, .-foo
+       .section        .text.main,"ax",@progbits
+.global        main
+       .type   main, @function
+main:
+       push r28
+       push r29
+       in r28,__SP_L__
+       in r29,__SP_H__
+/* prologue: function */
+/* frame size = 0 */
+/* stack size = 2 */
+.L__stack_usage = 2
+       call foo
+       lds r24,g
+       lds r25,g+1
+       sbiw r24,1
+       sts g+1,r25
+       sts g,r24
+       lds r24,g
+       lds r25,g+1
+/* epilogue start */
+       pop r29
+       pop r28
+       ret
+       .size   main, .-main
+       .ident  "GCC: (GNU) 6.0.0 20150630 (experimental)"
+.global __do_clear_bss