/* Calculate fixup value for reference. */
static int
-calc_fixup (bfd_vma addr, asection *sec)
+calc_fixup (bfd_vma start, bfd_vma size, asection *sec)
{
+ bfd_vma end = start + size;
int i, fixup = 0;
if (sec == NULL || sec->relax == NULL)
/* Look for addr in relax table, total fixup value. */
for (i = 0; i < sec->relax_count; i++)
{
- if (addr <= sec->relax[i].addr)
+ if (end <= sec->relax[i].addr)
break;
+ if ((end != start) && (start > sec->relax[i].addr))
+ continue;
fixup += sec->relax[i].size;
}
-
return fixup;
}
bfd_vma nraddr;
/* Get the new reloc address. */
- nraddr = irel->r_offset - calc_fixup (irel->r_offset, sec);
+ nraddr = irel->r_offset - calc_fixup (irel->r_offset, 0, sec);
switch ((enum elf_microblaze_reloc_type) ELF32_R_TYPE (irel->r_info))
{
default:
/* Only handle relocs against .text. */
if (isym->st_shndx == shndx
&& ELF32_ST_TYPE (isym->st_info) == STT_SECTION)
- irel->r_addend -= calc_fixup (irel->r_addend, sec);
+ irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
}
break;
case R_MICROBLAZE_NONE:
int sfix, efix;
bfd_vma target_address;
target_address = irel->r_addend + irel->r_offset;
- sfix = calc_fixup (irel->r_offset, sec);
- efix = calc_fixup (target_address, sec);
+ sfix = calc_fixup (irel->r_offset, 0, sec);
+ efix = calc_fixup (target_address, 0, sec);
irel->r_addend -= (efix - sfix);
/* Should use HOWTO. */
microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
int sfix, efix;
bfd_vma target_address;
target_address = irel->r_addend + irel->r_offset + INST_WORD_SIZE;
- sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, sec);
- efix = calc_fixup (target_address, sec);
+ sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
+ efix = calc_fixup (target_address, 0, sec);
irel->r_addend -= (efix - sfix);
microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
+ INST_WORD_SIZE, irel->r_addend);
}
}
- irelscan->r_addend -= calc_fixup (irelscan->r_addend, sec);
+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
}
else if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_SYM_OP_SYM)
{
}
irelscan->r_addend -= calc_fixup (irel->r_addend
+ isym->st_value,
+ 0,
sec);
}
}
unsigned long instr = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
immediate = instr & 0x0000ffff;
target_address = immediate;
- offset = calc_fixup (target_address, sec);
+ offset = calc_fixup (target_address, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
+ INST_WORD_SIZE);
immediate = (instr_hi & 0x0000ffff) << 16;
immediate |= (instr_lo & 0x0000ffff);
- offset = calc_fixup (irelscan->r_addend, sec);
+ offset = calc_fixup (irelscan->r_addend, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
}
immediate = (instr_hi & 0x0000ffff) << 16;
immediate |= (instr_lo & 0x0000ffff);
target_address = immediate;
- offset = calc_fixup (target_address, sec);
+ offset = calc_fixup (target_address, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
microblaze_bfd_write_imm_value_64 (abfd, ocontents
for (isym = isymbuf; isym < isymend; isym++)
{
if (isym->st_shndx == shndx)
- isym->st_value =- calc_fixup (isym->st_value, sec);
+ {
+ isym->st_value -= calc_fixup (isym->st_value, 0, sec);
+ if (isym->st_size)
+ isym->st_size -= calc_fixup (isym->st_value, isym->st_size, sec);
+ }
}
/* Now adjust the global symbols defined in this section. */
isym = isymbuf + symtab_hdr->sh_info;
- isymend = isymbuf + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
- for (sym_index = 0; isym < isymend; isym++, sym_index++)
+ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)) - symtab_hdr->sh_info;
+ for (sym_index = 0; sym_index < symcount; sym_index++)
{
sym_hash = elf_sym_hashes (abfd)[sym_index];
- if (isym->st_shndx == shndx
- && (sym_hash->root.type == bfd_link_hash_defined
+ if ((sym_hash->root.type == bfd_link_hash_defined
|| sym_hash->root.type == bfd_link_hash_defweak)
&& sym_hash->root.u.def.section == sec)
- {
- sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
- sec);
- }
- }
+ {
+ sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
+ 0, sec);
+ if (sym_hash->size)
+ sym_hash->size -= calc_fixup (sym_hash->root.u.def.value,
+ sym_hash->size, sec);
+ }
+ }
/* Physically move the code and change the cooked size. */
dest = sec->relax[0].addr;
--- /dev/null
+
+Symbol table '.symtab' contains 29 entries:
+ Num: Value Size Type Bind Vis Ndx Name
+ 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
+ 1: 00000050 0 SECTION LOCAL DEFAULT 1
+ 2: 00000058 0 SECTION LOCAL DEFAULT 2
+ 3: 00000000 0 FILE LOCAL DEFAULT ABS relax_size.o
+ 4: 00000050 8 NOTYPE LOCAL DEFAULT 1 func
+ 5: 00000058 0 NOTYPE LOCAL DEFAULT 1 label
+ 6: 00000000 0 FILE LOCAL DEFAULT ABS
+ 7: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _fdata
+ 8: 00000058 0 NOTYPE GLOBAL DEFAULT 1 _etext
+ 9: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _essrw
+ 10: 00000058 0 NOTYPE GLOBAL DEFAULT 1 _heap_end
+ 11: 00000058 0 NOTYPE GLOBAL DEFAULT 1 _heap_start
+ 12: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _ssro_size
+ 13: 00000050 0 NOTYPE GLOBAL DEFAULT 1 _ftext
+ 14: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _essro
+ 15: 00000400 0 NOTYPE GLOBAL DEFAULT ABS _STACK_SIZE
+ 16: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _HEAP_SIZE
+ 17: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _ssrw_size
+ 18: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _stack_end
+ 19: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _edata
+ 20: 00000458 0 NOTYPE GLOBAL DEFAULT 2 _end
+ 21: 00000058 0 NOTYPE GLOBAL DEFAULT 1 _heap
+ 22: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _ssro
+ 23: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _ssrw
+ 24: 00000458 0 NOTYPE GLOBAL DEFAULT 2 _stack
+ 25: 00000050 0 NOTYPE GLOBAL DEFAULT ABS _TEXT_START_ADDR
+ 26: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _frodata
+ 27: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _fbss
+ 28: 00000058 0 NOTYPE GLOBAL DEFAULT 2 _erodata
--- /dev/null
+
+Symbol table '.symtab' contains 31 entries:
+ Num: Value Size Type Bind Vis Ndx Name
+ 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
+ 1: 00000050 0 SECTION LOCAL DEFAULT 1
+ 2: 00000060 0 SECTION LOCAL DEFAULT 2
+ 3: 00000000 0 FILE LOCAL DEFAULT ABS relax_size2.o
+ 4: 00000050 4 NOTYPE LOCAL DEFAULT 1 func
+ 5: 00000054 0 NOTYPE LOCAL DEFAULT 1 label
+ 6: 00000054 8 NOTYPE LOCAL DEFAULT 1 func2
+ 7: 0000005c 0 NOTYPE LOCAL DEFAULT 1 label2
+ 8: 00000000 0 FILE LOCAL DEFAULT ABS
+ 9: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _fdata
+ 10: 0000005c 0 NOTYPE GLOBAL DEFAULT 1 _etext
+ 11: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _essrw
+ 12: 00000060 0 NOTYPE GLOBAL DEFAULT 1 _heap_end
+ 13: 00000060 0 NOTYPE GLOBAL DEFAULT 1 _heap_start
+ 14: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _ssro_size
+ 15: 00000050 0 NOTYPE GLOBAL DEFAULT 1 _ftext
+ 16: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _essro
+ 17: 00000400 0 NOTYPE GLOBAL DEFAULT ABS _STACK_SIZE
+ 18: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _HEAP_SIZE
+ 19: 00000000 0 NOTYPE GLOBAL DEFAULT ABS _ssrw_size
+ 20: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _stack_end
+ 21: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _edata
+ 22: 00000460 0 NOTYPE GLOBAL DEFAULT 2 _end
+ 23: 00000060 0 NOTYPE GLOBAL DEFAULT 1 _heap
+ 24: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _ssro
+ 25: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _ssrw
+ 26: 00000460 0 NOTYPE GLOBAL DEFAULT 2 _stack
+ 27: 00000050 0 NOTYPE GLOBAL DEFAULT ABS _TEXT_START_ADDR
+ 28: 0000005c 0 NOTYPE GLOBAL DEFAULT 2 _frodata
+ 29: 00000060 0 NOTYPE GLOBAL DEFAULT 2 _fbss
+ 30: 0000005c 0 NOTYPE GLOBAL DEFAULT 2 _erodata