This is the mail archive of the binutils@sourceware.org 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: [PATCH] Use offsets instead of addresses in ELF_SECTION_IN_SEGMENT


On Tue, May 22, 2018 at 11:52:15AM +0100, Alan Hayward wrote:
> Use sh_offset and p_offset instead of sh_addr and p_vaddr when calculating if a section fits in a segment. Both methods are valid when using the GNU linker.
> 
> This change makes ELF_SECTION_IN_SEGMENT consistent with BFD _bfd_elf_make_section_from_shdr(), which has used offsets to calculate LMA since 2008.

LMA is not VMA.  The code you referenced doesn't really support the
change you propose, nor did you say exactly why the change is needed.

> diff --git a/include/elf/internal.h b/include/elf/internal.h
> index 05f9fab89c..5d93e0070e 100644
> --- a/include/elf/internal.h
> +++ b/include/elf/internal.h
> @@ -347,9 +347,9 @@ struct elf_segment_map
>         || ((sec_hdr)->sh_flags & SHF_ALLOC) == 0			\
>         || ((sec_hdr)->sh_addr >= (segment)->p_vaddr			\
>  	   && (!(strict)						\
> -	       || ((sec_hdr)->sh_addr - (segment)->p_vaddr		\
> +	       || ((sec_hdr)->sh_offset - (segment)->p_offset		\
>  		   <= (segment)->p_memsz - 1))				\
> -	   && (((sec_hdr)->sh_addr - (segment)->p_vaddr			\
> +	   && (((sec_hdr)->sh_offset - (segment)->p_offset		\
>  		+ ELF_SECTION_SIZE(sec_hdr, segment))			\
>  	       <= (segment)->p_memsz)))					\
>     /* No zero size sections at start or end of PT_DYNAMIC.  */		\

We test sh_offset already, just above the code you are patching.  So I
think this VMA test should continue to test sh_addr.

Now there are reasons you might want to disable the VMA checks
entirely, for example when overlays are present.  To do that, use
ELF_SECTION_IN_SEGMENT_1 with check_vma false.  See the example in
elf.c assign_files_positions_for_load_sections.

-- 
Alan Modra
Australia Development Lab, IBM


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