[PATCH] x86: Add x86_is_elf to optimize out the ELF check

Jan Beulich jbeulich@suse.com
Thu Sep 26 10:35:30 GMT 2024


On 26.09.2024 12:22, H.J. Lu wrote:
> On Tue, Sep 24, 2024 at 5:57 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> On 24.09.2024 11:10, H.J. Lu wrote:
>>>  On Tue, Sep 24, 2024 at 4:19 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>
>>>> On 24.09.2024 00:56, H.J. Lu wrote:
>>>>> Add x86_is_elf and replace IS_ELF with x86_is_elf () so that compiler
>>>>> can optimize out the ELF check when OBJ_ELF is defined and OBJ_MAYBE_ELF
>>>>> isn't defined.
>>>>>
>>>>> * config/tc-i386.c (x86_is_elf): New function.
>>>>> (check_cpu_arch_compatible): Replace IS_ELF with x86_is_elf ().
>>>>> (i386_arch): Likewise.
>>>>> (i386_mach): Likewise.
>>>>> (tc_i386_fix_adjustable): Likewise.
>>>>> (i386_assemble): Likewise.
>>>>> (need_plt32_p): Likewise.
>>>>> (x86_cleanup): Likewise.
>>>>> (output_insn): Likewise.
>>>>> (lex_got): Likewise.
>>>>> (s_insn): Likewise.
>>>>> (md_estimate_size_before_relax): Likewise.
>>>>> (md_apply_fix): Likewise.
>>>>> (md_parse_option): Likewise.
>>>>> (i386_target_format): Likewise.
>>>>> (i386_validate_fix): Likewise.
>>>>> (tc_gen_reloc): Likewise.
>>>>>
>>>>
>>>> Sadly there's no actual patch, so I can only guess what it does. I think
>>>> we don't need this anymore, with the plan to do away with OBJ_MAYBE_ELF
>>>
>>> OBJ_MAYBE_ELF is used by the configure option like,
>>>
>>> --enable-targets=x86_64-mingw64
>>>
>>> I don't think we should remove it unless there is a very good reason.
>>
>> You give precisely an example of why we should remove it: That target
>> wants PE/COFF support, but what it gets as emulation is plain COFF.
>> That's wrong. I was actually half way through addressing this aspect,
>> when it occurred to me that the issue is far worse. While even COFF
>> has more than 2 sub-flavors (go32 for example), ELF has yet more
>> (GNU, Solaris, FreeBSD, Lynx, NetBSD, VxWorks, and maybe more). If we
>> wanted to get things right, all TE_* checks anywhere (including ones
>> which are presently missing anyway) would need to become runtime
>> checks, and we'd need an emulation for each flavor. That's simply
>> going to be unwieldy. Hence Nick and I agreed that we'd drop
>> emulation support for i386 instead. (Note also that there's been no
>> testing of those emulations in the x86 gas testsuite, which may be
>> part of why no issues were ever noticed with the wrong COFF emulation
>> being chosen when enabling a PE/COFF target as secondary one.)
> 
> When will OBJ_MAYBE_ELF be removed?  If it won't happen soon,
> I'd like to check my patch.

As said, I'm intending to get to this (as in: re-working the patches
fixing the shortcomings to become simple removal); if all goes well it
may be as soon as tomorrow. Please can you be a little patient? There's
no reason to rush here afaics, and there's also no reason to introduce
extra code churn.

Jan


More information about the Binutils mailing list