Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 588632 - sys-devel/gcc: new USE=mpx flag duplicates USE_EXPAND flag cpu_flags_x86_mpx
Summary: sys-devel/gcc: new USE=mpx flag duplicates USE_EXPAND flag cpu_flags_x86_mpx
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-11 21:59 UTC by Anthony Basile
Modified: 2016-07-13 15:57 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Basile gentoo-dev 2016-07-11 21:59:34 UTC
In commit 519631a4, USE=mpx is introduced to toolchain.eclass to add support for the new Intel MPX (see bug #578396).  However, we've been using CPU_FLAGS_X86 to track amd64 cpu flags.  In fact, that commit even adds a description of cpu_flags_x86_mpx to profiles/desc/cpu_flags_x86.desc and does all the appropriate maskings in base/use.mask, and but just uses mpx in toolchain.eclass.

We should pick one or the other flag, and not have duplicates.  Preferably, we should use the USE_EXPAND flag because its global and stylistically follows how we treat all other amd64 flags.
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-07-12 10:50:33 UTC
The only reason I see for not using CPU_FLAGS_* would be if users may want to have the flag enabled independently of the CPU support. For example, app-emulation/bochs uses USE=avx to control emulating AVX instructions (!= cpu_flags_x86_avx that is for using AVX instructions from host CPU). But I don't think this applies here.
Comment 2 Ryan Hill (RETIRED) gentoo-dev 2016-07-12 22:41:15 UTC
mpx means "build the libmpx runtime library", not "use mpx instructions".  There is no reason to assume that just because your host CPU supports it you want to build the instrumentation library.
Comment 3 Ryan Hill (RETIRED) gentoo-dev 2016-07-12 22:45:39 UTC
maybe libmpx would be a better flag name.
Comment 4 Anthony Basile gentoo-dev 2016-07-12 23:03:22 UTC
(In reply to Ryan Hill from comment #2)
> mpx means "build the libmpx runtime library", not "use mpx instructions". 
> There is no reason to assume that just because your host CPU supports it you
> want to build the instrumentation library.

Well they're not completely independent since you can't build libmpx if your cpu doesn't support mpx instructions.  This doesn't seem so different from what we do in other packages (eg vlc) where one can turn on/off code which requires certain cpu instructions for optimization (eg mmx), only in this case its instrumentation not optimization.  If your cpu supports mmx and you want vlc built without it, you do "media-video/vlc -cpu_flags_x86_mmx".  Similarly, if your cpu supports mpx and you want gcc built with libmpx, you do "sys-devel/gcc -cpu_flags_x86_mpx".

Since I've never used mpx, what I don't know is whether there's some gcc switch that allows you to build executables with/without mpx instrumentation.  I would assume there is and that its off by default.  In which case I would think a sane default is build libmpx if your cpu supports it, but compile using gcc with mpx instrumentation off.  Then libmpx is there if you want to use it for debugging or hardening, but you have to explicitly invoke it.
Comment 5 Anthony Basile gentoo-dev 2016-07-12 23:04:45 UTC
(In reply to Anthony Basile from comment #4)
> Similarly, if your cpu supports mpx and you want gcc built with libmpx, you
> do "sys-devel/gcc -cpu_flags_x86_mpx".
> 

That should read "and you want gcc built without libmpx, you do ..."
Comment 6 Ryan Hill (RETIRED) gentoo-dev 2016-07-13 00:58:13 UTC
(In reply to Anthony Basile from comment #4)
> (In reply to Ryan Hill from comment #2)
> > mpx means "build the libmpx runtime library", not "use mpx instructions". 
> > There is no reason to assume that just because your host CPU supports it you
> > want to build the instrumentation library.
> 
> Well they're not completely independent since you can't build libmpx if your
> cpu doesn't support mpx instructions.

Sure you can.  You can even run binaries built with mpx instructions on systems that don't support it (though I don't know why you'd want to). :)

MPX is enabled by building with -mmpx and some -f flags and linking with -lmpx.  So you need libmpx enabled on both the host and the target for everything to work.  cpu_flags are target flags, so I can see why it would make some sense to put it there, but it doesn't when host != target.  Maybe that's rare enough that it doesn't matter much though.  I'm on the fence now, so your call.
Comment 7 Anthony Basile gentoo-dev 2016-07-13 01:35:59 UTC
(In reply to Ryan Hill from comment #6)
> (In reply to Anthony Basile from comment #4)
> > (In reply to Ryan Hill from comment #2)
> > > mpx means "build the libmpx runtime library", not "use mpx instructions". 
> > > There is no reason to assume that just because your host CPU supports it you
> > > want to build the instrumentation library.
> > 
> > Well they're not completely independent since you can't build libmpx if your
> > cpu doesn't support mpx instructions.
> 
> Sure you can.  You can even run binaries built with mpx instructions on
> systems that don't support it (though I don't know why you'd want to). :)

I don't get that.  If your assembly contains op codes that your cpu can't execute, won't it fault?  Or is libmpx generated with some internal logic to detect if the cpu has mpx and just stubs out any non-executable code?

Anyhow if this is the case, then I think we should leave things as is and maybe just improve the metadata.xml description for the flag which currently reads "Enable support for Intel Memory Protection Extensions (MPX)".  Maybe "Enable code instrumentation based on Intel Memory Protection Extensions (MPX)".

> 
> MPX is enabled by building with -mmpx and some -f flags and linking with
> -lmpx.  So you need libmpx enabled on both the host and the target for
> everything to work.  cpu_flags are target flags, so I can see why it would
> make some sense to put it there, but it doesn't when host != target.  Maybe
> that's rare enough that it doesn't matter much though.  I'm on the fence
> now, so your call.

I already mentioned the case where host != target to mgorny who brought up the this flag issue to me in IRC.  I think mpx during cross compile is rare enough.

Actually, I've been reading up on mpx and I wonder about its usefulness in general given that it generates some false positives and has perferance hits.  For future reference:

https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler

https://github.com/google/sanitizers/wiki/AddressSanitizerIntelMemoryProtectionExtensions



Anyhow, bottom line, I think leave things as they are.
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-07-13 05:05:58 UTC
Let's ask the opposite question then: do we want cpu_flags_x86_mpx for anything? Is there a case for e.g. inline mpx assembly in packages? Do we want it auto-enabled on CPUs supporting mpx?
Comment 9 Ryan Hill (RETIRED) gentoo-dev 2016-07-13 06:09:20 UTC
No I don't think so.  mpx support in a package would just mean building it with the necessary compiler flags.  There's performance and memory costs involved so it shouldn't be on by default.
Comment 10 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-07-13 07:19:22 UTC
Then I think it'd better to remove it from cpu_flags_x86 as it doesn't match the way other flags are used there.
Comment 11 Anthony Basile gentoo-dev 2016-07-13 14:54:41 UTC
(In reply to Michał Górny from comment #10)
> Then I think it'd better to remove it from cpu_flags_x86 as it doesn't match
> the way other flags are used there.

Yeah sounds good to me.
Comment 12 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-07-13 15:57:20 UTC
commit 85af9c870835e3fa9d949506e34272c0425f437e
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: Wed Jul 13 17:55:05 2016
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: Wed Jul 13 17:56:56 2016

    profiles: Nuke cpu_flags_x86_mpx, #588632
    
    Remove the mpx flag from CPU_FLAGS_X86. Since mpx has memory and
    performance costs, this is not a flag users expect to have automatically
    enabled based on CPU abilities.