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] x86: Don't remove empty x86 properties


On Tue, Dec 4, 2018 at 5:51 PM Cary Coutant <ccoutant@gmail.com> wrote:
>
> > > In the psABI, you have described both ISA_1_USED and FEATURE_2_USED as
> > > "their support in the hardware is optional". Yet:
> > >
> > > (a) You've assigned values for both of these in the OR_AND range,
> > > which you've described earlier in this thread as meaning "It is not OK
> > > if run-time doesn't have the feature the program requires."
>
> You haven't responded to this. Either the psABI is wrong or your
> explanation earlier in this thread about OR_AND is wrong. Which is it?
>
> In bfd, you treat the USED properties as OR_AND properties, where you
> remove the property if one file doesn't provide it, and you treat the
> NEEDED properties as OR properties. Given the psABI descriptions of
> the USED and NEEDED properties, I think you've got them backwards.

There are

GNU_PROPERTY_X86_UINT32_OR_LO..GNU_PROPERTY_X86_UINT32_OR_HI
A bit in the output pr_data field is set if it is set in any
relocatable input pr_data
fields. If all bits in the the output pr_data field are zero, this
property should be
removed from output. If the bit is 1, some input relocatables have the
feature. If
the bit is 0 or the property is missing, it is unknown whether any
input relocatables
have the feature.

GNU_PROPERTY_X86_UINT32_OR_AND_LO..GNU_PROPERTY_X86_UINT32_OR_AND_HI
A bit in the output pr_data field is set if it is set in any
relocatable input pr_data
fields and this property is present in all relocatable input files. A
missing property
implies that its bits have unknown values. When all bits in the the
output pr_data
field are zero, this property should not be removed from output to
indicate it has
zero in all bits. If the property is in output, all input relocatables
have the property.
If the bit is 1, some input relocatables have the feature. If the bit
is 0, none of input
relocatables have the feature.

How do they differ from bfd linker?

> > > Why do CMOV, SSE, SSE2, AVX, and AVX512F go in ISA_1_USED, but AVX2
> > > goes in ISA_1_NEEDED?
> >
> > When main () executes AVX2 instructions unconditionally, AVX2 is needed.
> > main () may also call other functions which use CMOV, SSE, SSE2, AVX,
> > and AVX512F.
> >
> > > Why do x86, x87, XMM, YMM, ZMM, FXSR, XSAVE, and XSAVEC go in
> > > FEATURE_2_USED, but XMM and YMM go in FEATURE_2_NEEDED?
> >
> > When main () executes instructions with XMM and YMM registers unconditionally,
> > XMM and YMM are needed.  main () may also call other functions which use
> > x86, x87, XMM, YMM, ZMM, FXSR, XSAVE, and XSAVEC.
>
> It sounds like you're telling me that you use NEEDED to describe
> features that main() uses, and USED to describe what features may be

An x86 program main () may contain AVX512 instructions, whose usage is
guarded by CPUID.  NEEDED describes features that main() uses without
CPUID check.  In this case, AVX512 is USED, not NEEDED.

> used by functions that main() calls. That can't be what you mean --
> how is that a useful distinction? And how would the linker even
> determine that?

Linker just merges properties according to rules in x86-64 psABI.

> > > How exactly are you expecting these properties to be treated by the loader?
> >
> > For example, it can be used to check if a program contains any SSE instructions.
> > One may want to build a program without SSE.  It can be used to verify that.
> > Unlike ISA_1_USED, only 1 bit in ISA_1_NEEDED is accurate.   We can't
> > use ISA_1_NEEDED to check if a program has any SSE instructions.
> >
> > > For USED (but optional) features, who is the intended consumer? A
> > > loader can't use them to reject the program on reduced-capability
> > > hardware, since those features are described as optional. Code tagged
> > > with a used-but-optional feature presumably has been written to
> > > dynamically test for the presence of a capability, and use it if it's
> > > present, falling back to a less-preferred mechanism if it's not. Such
> > > a property might be useful for link-time selection of variant
> > > implementations of a routine, or even for load-time selection, but
> > > only if the property remains attached to the specific entry point. As
> > > a binary-wide property, I don't see how it would be of much use. If
> > > the intended consumer is nothing more than a human reader of objdump
> > > output, that's fine, but you're going to an awful lot of work if
> > > that's it.
> > >
> > > For NEEDED features, the intent is clearly that the loader can
> > > determine whether the hardware is capable of executing a particular
> > > binary, and rejecting it gracefully if it's not (as opposed to letting
> > > it core dump when it tries to use an absent feature -- or worse!). For
> > > these, it seems silly to discard the whole set of NEEDED features when
> > > even a single input file is missing the property -- after all, even if
> > > that missing input file might need some unique features, it's still
> > > the case that the ones we do know about from other files are still
> > > needed, and it's still desirable to let the loader reject the binary
> > > if it can. This is why I don't really understand your motivation for
> > > the OR_AND rule.
> >
> > OR_AND is for accurate 0 bit.  Loader may decide to load a program
> > only if SSE bit is 0.
>
> Please explain what you expect the loader (and other consumers) to do
> with the USED and NEEDED bits. This explanation ought to be in the
> psABI.
>

How about this?

GNU_PROPERTY_X86_FEATURE_2_USED The x86 processor features indicated
by the corresponding bits are used in program. Their support in the hardware is
optional. Its absence in an x86 ELF binary implies that any x86
processor features
may be used. GNU_PROPERTY_X86_FEATURE_2_USED can be used to check
for features used in the program.

GNU_PROPERTY_X86_FEATURE_2_NEEDED The x86 processor features
indicated by the corresponding bits are used in program and they must be
supported by the hardware. Loader may refuse to load the program whose
GNU_PROPERTY_X86_FEATURE_2_NEEDED features aren’t supported by the
hardware.

GNU_PROPERTY_X86_ISA_1_NEEDED The x86 instruction sets indicated by the
corresponding bits are used in program and they must be supported by
the hardware.
Loader may refuse to load the program whose GNU_PROPERTY_X86_ISA_1_NEEDED
ISAs aren’t supported by the hardware.

GNU_PROPERTY_X86_ISA_1_USED The x86 instruction sets indicated by the
corresponding bits are used in program. Their support in the hardware
is optional.
GNU_PROPERTY_X86_ISA_1_USED can be used to check for ISAs used in the
program.

-- 
H.J.


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