This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Allow STT_SECTION + offset for SHF_MERGE sections


On Mon, Nov 19, 2001 at 01:51:31PM +0100, Jakub Jelinek wrote:
> > 
> > How about putting all the above into a function that is called instead of
> > _bfd_final_link_relocate (and itself calls _bfd_final_link_relocate)?
> 
> This code differs between REL arches (where it is a lot backend dependent)
> and RELA arches (where the code is basically the same, but the basic question
> is whether it can modify rel->r_addend or not. If it could, it would mean
> just calling a special routine which would do:

I don't see why you shouldn't modify the reloc.  In fact, given that ld
has --embedded-relocs, I think you _should_ modify the reloc for RELA.

> bfd_vma
> _bfd_elf_rela_local_sym (abfd, sym, sec, rel)
>      bfd *abfd;
>      Elf_Internal_Sym *sym;
>      asection *sec;
>      Elf_Internal_Rela *rel;
> {
>   bfd_vma relocation;
> 
>   relocation = (sec->output_section->vma
> 		+ sec->output_offset
> 		+ sym->st_value);
>   if ((sec->flags & SEC_MERGE)
>       && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
>     {
>       asection *msec;
> 
>       msec = sec;
>       rel->r_addend =
> 	_bfd_merged_section_offset (abfd, &msec,
> 				    elf_section_data (sec)->merge_info,
> 				    sym->st_value + addend, (bfd_vma) 0)
> 	- relocation;
>       rel->r_addend += msec->output_section->vma + msec->output_offset;
>     }
>   return relocation;
> }
> 
> and replace
> (1)	relocation = (sec->output_section->vma
> 		      + sec->output_offset
> 		      + sym->st_value);
> with
> (2)	relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
> 
> I have checked and all RELA backends use code (1) so it would be pretty easy
> to just replace it all with (2). The only exception is elf32-hppa.c, which
> does:
>           relocation = ((ELF_ST_TYPE (sym->st_info) == STT_SECTION
>                            ? 0 : sym->st_value)
>                          + sym_sec->output_offset
>                          + sym_sec->output_section->vma);
> instead. Are the STT_SECTION symbols ever having st_value != 0 in
> relocatable objects on HPPA?

This is old code that is likely redundant.  I've never understood the need
for it, and for elf32_hppa_add_symbol_hook.  I'll ask Jeff.

> This IMHO cannot be done at _bfd_final_link_relocate time, since that is too
> late (many backends might have created dynamic relocations from it already,
> etc.) and _bfd_final_link_relocate wouldn't know if it gets the relocation
> directly or whether backend didn't change it to GOT offset or whatever.

My comment regarding moving the code was for REL only, and the idea was
to localise code that modifies section contents.  Obviously a half-baked
idea though, given that you might have .got relocs.

Alan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]