[PATCH v2 3/5] bfd: avoid elf-sframe.c for SFrame-unaware targets

Indu Bhagat indu.bhagat@oracle.com
Sat Mar 7 00:33:57 GMT 2026


On 3/1/26 11:44 PM, Jan Beulich wrote:
> It is wasteful to build this file when it's not actually used. Limit it
> to targets actually using SFrame and introduce a compiler define
> (paralleling OBJ_MAYBE_ELF, as having similar purpose) to guard internal
> function decls.
> ---
> v2: Re-base.
> 
> --- a/bfd/configure
> +++ b/bfd/configure
> @@ -15829,14 +15829,14 @@ selarchs="$f"
>   tb=
>   
>   elf="elf.lo elflink.lo elf-strtab.lo elf-eh-frame.lo elf-properties.lo
> -     elf-sframe.lo dwarf1.lo dwarf2.lo"
> +     dwarf1.lo dwarf2.lo"
>   coffgen="coffgen.lo dwarf2.lo"
>   coff="cofflink.lo $coffgen"
>   ecoff="ecofflink.lo $coffgen"
>   xcoff="xcofflink.lo $coffgen"
>   
>   elf32_aarch64="elf32-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
> -elf64_aarch64="elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo elf-attrs.lo"
> +elf64_aarch64="elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo elf-attrs.lo elf-sframe.lo"
>   elf_arc="elf32-arc.lo elf32.lo elf-attrs.lo"
>   elf_arm="elf32-arm.lo elf32.lo elf-attrs.lo elf-vxworks.lo"
>   elf_csky="elf32-csky.lo elf32.lo elf-attrs.lo"
> @@ -16050,7 +16050,7 @@ do
>       rx_elf32_le_vec)		 tb="$tb elf32-rx.lo elf32.lo $elf" ;;
>       rx_elf32_linux_le_vec)	 tb="$tb elf32-rx.lo elf32.lo $elf" ;;
>       s390_elf32_vec)		 tb="$tb elf32-s390.lo elf32.lo elf-attrs.lo $elf" ;;
> -    s390_elf64_vec)		 tb="$tb elf64-s390.lo elf64.lo elf-attrs.lo $elf"; target_size=64 ;;
> +    s390_elf64_vec)		 tb="$tb elf64-s390.lo elf64.lo elf-attrs.lo elf-sframe.lo $elf"; target_size=64 ;;
>       score_elf32_be_vec)		 tb="$tb elf32-score.lo elf32-score7.lo elf32.lo elf64.lo $elf"; want64=true; target_size=64 ;;
>       score_elf32_le_vec)		 tb="$tb elf32-score.lo elf32-score7.lo elf32.lo elf64.lo $elf"; want64=true; target_size=64 ;;
>       sh_coff_vec)		 tb="$tb coff-sh.lo $coff" ;;
> @@ -16112,9 +16112,9 @@ do
>       wasm32_elf32_vec)            tb="$tb elf32-wasm32.lo elf32.lo $elf" ;;
>       x86_64_coff_vec)		 tb="$tb coff-x86_64.lo $coff"; target_size=64 ;;
>       x86_64_elf32_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf32.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_fbsd_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_sol2_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_fbsd_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_sol2_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
>       x86_64_mach_o_vec)		 tb="$tb mach-o-x86-64.lo" ;;
>       x86_64_pe_vec)		 tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
>       x86_64_pe_big_vec)		 tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
> @@ -16191,7 +16191,7 @@ if test x${all_targets} = xtrue ; then
>       esac
>     done
>     assocvecs=$f
> -  TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES"
> +  TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES -DOBJ_MAYBE_ELF_SFRAME"
>   else	# all_targets is true
>     # Only set these if they will be nonempty, for the clever echo.
>     havevecs=
> @@ -16207,6 +16207,7 @@ else	# all_targets is true
>       case "$i" in
>       elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
>       elf-attrs.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_ATTRIBUTES" ;;
> +    elf-sframe.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SFRAME" ;;
>       esac
>     done
>   fi	# all_targets is true
> --- a/bfd/configure.ac
> +++ b/bfd/configure.ac
> @@ -370,14 +370,14 @@ selarchs="$f"
>   tb=
>   
>   elf="elf.lo elflink.lo elf-strtab.lo elf-eh-frame.lo elf-properties.lo
> -     elf-sframe.lo dwarf1.lo dwarf2.lo"
> +     dwarf1.lo dwarf2.lo"
>   coffgen="coffgen.lo dwarf2.lo"
>   coff="cofflink.lo $coffgen"
>   ecoff="ecofflink.lo $coffgen"
>   xcoff="xcofflink.lo $coffgen"
>   
>   elf32_aarch64="elf32-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf32.lo elf-attrs.lo"
> -elf64_aarch64="elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo elf-attrs.lo"
> +elf64_aarch64="elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo elf-attrs.lo elf-sframe.lo"
>   elf_arc="elf32-arc.lo elf32.lo elf-attrs.lo"
>   elf_arm="elf32-arm.lo elf32.lo elf-attrs.lo elf-vxworks.lo"
>   elf_csky="elf32-csky.lo elf32.lo elf-attrs.lo"
> @@ -591,7 +591,7 @@ do
>       rx_elf32_le_vec)		 tb="$tb elf32-rx.lo elf32.lo $elf" ;;
>       rx_elf32_linux_le_vec)	 tb="$tb elf32-rx.lo elf32.lo $elf" ;;
>       s390_elf32_vec)		 tb="$tb elf32-s390.lo elf32.lo elf-attrs.lo $elf" ;;
> -    s390_elf64_vec)		 tb="$tb elf64-s390.lo elf64.lo elf-attrs.lo $elf"; target_size=64 ;;
> +    s390_elf64_vec)		 tb="$tb elf64-s390.lo elf64.lo elf-attrs.lo elf-sframe.lo $elf"; target_size=64 ;;
>       score_elf32_be_vec)		 tb="$tb elf32-score.lo elf32-score7.lo elf32.lo elf64.lo $elf"; want64=true; target_size=64 ;;
>       score_elf32_le_vec)		 tb="$tb elf32-score.lo elf32-score7.lo elf32.lo elf64.lo $elf"; want64=true; target_size=64 ;;
>       sh_coff_vec)		 tb="$tb coff-sh.lo $coff" ;;
> @@ -653,9 +653,9 @@ do
>       wasm32_elf32_vec)            tb="$tb elf32-wasm32.lo elf32.lo $elf" ;;
>       x86_64_coff_vec)		 tb="$tb coff-x86_64.lo $coff"; target_size=64 ;;
>       x86_64_elf32_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf32.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_fbsd_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> -    x86_64_elf64_sol2_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_vec)		 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_fbsd_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;
> +    x86_64_elf64_sol2_vec)	 tb="$tb elf64-x86-64.lo $elfxx_x86 elf64.lo elf-sframe.lo $elf"; target_size=64 ;;

Thanks Jan for the changes.

Is the case of adding elf-sframe.lo to fbsd_vec due to the following 
(config.bfd) ?

   x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
     targ_defvec=x86_64_elf64_fbsd_vec
     targ_selvecs="i386_elf32_fbsd_vec iamcu_elf32_vec i386_coff_vec 
i386_pei_vec x86_64_pe_vec x86_64_pei_vec i386_elf32_vec x86_64_elf64_vec"
     want64=true
     ;;

Also for sol2, do you think we should include elf-sframe.lo ? (I 
understand that your patch is making things cleaner than status quo.)

In essence, my concern is "leaking" SHT_GNU_SFRAME section type to 
freebsd and solaris.  To that end (unrelated to the current patch), is 
there a good way to detect OS (specifically GNU) in GAS ?  I thought 
about doing something like 'endswith (TARGET_OS, "gnu")' ...

Thanks

>       x86_64_mach_o_vec)		 tb="$tb mach-o-x86-64.lo" ;;
>       x86_64_pe_vec)		 tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
>       x86_64_pe_big_vec)		 tb="$tb pe-x86_64.lo pex64igen.lo $coff"; target_size=64 ;;
> @@ -732,7 +732,7 @@ if test x${all_targets} = xtrue ; then
>       esac
>     done
>     assocvecs=$f
> -  TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES"
> +  TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF -DOBJ_MAYBE_ELF_ATTRIBUTES -DOBJ_MAYBE_ELF_SFRAME"
>   else	# all_targets is true
>     # Only set these if they will be nonempty, for the clever echo.
>     havevecs=
> @@ -748,6 +748,7 @@ else	# all_targets is true
>       case "$i" in
>       elf.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF" ;;
>       elf-attrs.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_ATTRIBUTES" ;;
> +    elf-sframe.*) TDEFINES="$TDEFINES -DOBJ_MAYBE_ELF_SFRAME" ;;
>       esac
>     done
>   fi	# all_targets is true
> --- a/bfd/elf-bfd.h
> +++ b/bfd/elf-bfd.h
> @@ -2631,6 +2631,8 @@ extern bool _bfd_elf_eh_frame_entry_pres
>   extern bool _bfd_elf_maybe_strip_eh_frame_hdr
>     (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
>   
> +#ifdef OBJ_MAYBE_ELF_SFRAME
> +
>   extern bool _bfd_elf_sframe_present
>     (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
>   extern bool _bfd_elf_sframe_present_input_bfds
> @@ -2650,6 +2652,41 @@ extern bool _bfd_elf_write_section_sfram
>   extern bool _bfd_elf_set_section_sframe
>     (bfd *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
>   
> +#else /* !OBJ_MAYBE_ELF_SFRAME */
> +
> +static inline bool _bfd_elf_sframe_present
> +  (struct bfd_link_info *info ATTRIBUTE_UNUSED)
> +{ return false; }
> +static inline bool _bfd_elf_sframe_present_input_bfds
> +  (struct bfd_link_info *info ATTRIBUTE_UNUSED)
> +{ return false; }
> +static inline bool _bfd_elf_parse_sframe
> +  (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED,
> +   asection *sec ATTRIBUTE_UNUSED,
> +   struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED)
> +{ return false; }
> +static inline bool _bfd_elf_discard_section_sframe
> +  (asection *sec ATTRIBUTE_UNUSED,
> +  bool (*reloc_symbol_deleted_p) (bfd_vma, void *) ATTRIBUTE_UNUSED,
> +  struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED)
> +{ return false; }
> +static inline bool _bfd_elf_merge_section_sframe
> +  (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED,
> +   asection *sec ATTRIBUTE_UNUSED, bfd_byte *contents ATTRIBUTE_UNUSED)
> +{ return false; }
> +static inline bfd_vma _bfd_elf_sframe_section_offset
> +  (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED,
> +   asection *sec ATTRIBUTE_UNUSED, bfd_vma offset)
> +{ return offset; }
> +static inline bool _bfd_elf_write_section_sframe
> +  (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED)
> +{ return true; }
> +static inline bool _bfd_elf_set_section_sframe
> +  (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED)
> +{ return false; }
> +
> +#endif /* OBJ_MAYBE_ELF_SFRAME */
> +
>   extern bool _bfd_elf_hash_symbol
>     (struct elf_link_hash_entry *) ATTRIBUTE_HIDDEN;
>   
> 



More information about the Binutils mailing list