Should I use
Code: Select all
-march=<my-cpu> -mtune=genericCode: Select all
-march=<my-cpu> -mtune=<my-cpu>Code: Select all
-march=<my-cpu>Code: Select all
gcc -### -c -march=native /usr/include/stdlib.hCode: Select all
-march=native
Code: Select all
-march=<my-cpu> -mtune=genericCode: Select all
-march=<my-cpu> -mtune=<my-cpu>Code: Select all
-march=<my-cpu>Code: Select all
gcc -### -c -march=native /usr/include/stdlib.hCode: Select all
-march=native
Code: Select all
-march=nativeCode: Select all
-mindirect-branch=thunk
This has no effect without -O2. Moreover, as mentioned in another thread, one probably should also addNeddySeagoon wrote:Code: Select all
-mindirect-branch=thunk
Code: Select all
-fno-plt -mfunction-return=thunkCode: Select all
-fstack-protector-strong -pie -fPIE -fstack-check=specific -Wl,-z,now -Wl,-z,relro

They eliminate some further prediction not covered by -mindirect-branch=thunk: In binutils, -Wl,-z,retpolineplt was not implemented, because they said that -fno-plt should be used instead.


NeddySeagoonNeddySeagoon wrote:Cuong Nguyen,
That sounds like a build farm you have there, so maybe you do want to use distributed compiling.

Is that default for hardened profile? As advised by Gentoo Hardened FAQs: "let the profile do its jobs" https://wiki.gentoo.org/wiki/Hardened/F ... _CFLAGS.3Fmv wrote: for spectre. But IMHO spectre is overestimated. More valuable are other protection measurements likein CFLAGS, CXXFLAGS; LDFLAGS. Fortunately, the former 2(or also the 3rd?) are meanwhile default with gcc[ssp pie].Code: Select all
-fstack-protector-strong -pie -fPIE -fstack-check=specific -Wl,-z,now -Wl,-z,relro
The hardened gcc uses them implicitly by default (i.e. they do not have to be specified). But hardened uses even -fstack-protector-all which considerably slows down for practically no security gain. Moreover, I had other issues with hardened, and it is not so simple to switch gcc profile package-dependent automatically as it is to filter flags in /etc/portage/bashrc (and when you switch gcc profile you would have to add the non-problematic flags anyway).Cuong Nguyen wrote:Is that default for hardened profile? As advised by Gentoo Hardened FAQs: "let the profile do its jobs"mv wrote: for spectre. But IMHO spectre is overestimated. More valuable are other protection measurements likein CFLAGS, CXXFLAGS; LDFLAGS. Fortunately, the former 2(or also the 3rd?) are meanwhile default with gcc[ssp pie].Code: Select all
-fstack-protector-strong -pie -fPIE -fstack-check=specific -Wl,-z,now -Wl,-z,relro


mv wrote:Cuong Nguyen wrote:I don't like hardened profile, too, as it renders other problems when switching profiles. Now I copy settings from hardened profile (i.e. "hardened" use-flag) to my local /etc/portage/profile or starting with hardened profile, re-emerge toolchain consists of gcc, binutils, glibc, virtual/libc, libtool, protect it from re-emerging by package.provided file.mv wrote: Moreover, I had other issues with hardened, and it is not so simple to switch gcc profile package-dependent automatically as it is to filter flags in /etc/portage/bashrc (and when you switch gcc profile you would have to add the non-problematic flags anyway).
The otherway is instead of switching profiles I create combined profiles on local and link it with hardened profile.
Now I put fstack flags explicitly into C, CXX and LDFLAGSI am just wondering why I have to put the same flags into C CXX and LDFLAGS?Code: Select all
CFLAGS="${CFLAGS} -fstack-protector-strong -pie -fPIE -fstack-check=specific" CFLAGS="${CFLAGS} -fno-plt -mfunction-return=thunk" CXXFLAGS="${CFLAGS}" LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--sort-common -Wl,--hash-style=both -Wl,-z,relro -Wl,-znow" LDFLAGS="${LDFLAGS} -fstack-protector-strong -pie -fPIE -fstack-check=specific" LDFLAGS="${LDFLAGS} -fno-plt -mfunction-return=thunk"
Best regards

mv,mv wrote:This has no effect without -O2. Moreover, as mentioned in another thread, one probably should also addNeddySeagoon wrote:Code: Select all
-mindirect-branch=thunkfor spectre. But IMHO spectre is overestimated. More valuable are other protection measurements likeCode: Select all
-fno-plt -mfunction-return=thunkin CFLAGS, CXXFLAGS; LDFLAGS. Fortunately, the former 2(or also the 3rd?) are meanwhile default with gcc[ssp pie].Code: Select all
-fstack-protector-strong -pie -fPIE -fstack-check=specific -Wl,-z,now -Wl,-z,relro
Code: Select all
../lib64/Scrt1.o:function _start: error: undefined reference to 'main'Yes, for several packages they need to be filtered.Cuong Nguyen wrote:-pie -fPIE flags break several packages

Thank you mv,mv wrote:Yes, for several packages they need to be filtered.Cuong Nguyen wrote:-pie -fPIE flags break several packages
However, you always catch this during compile time.
To be honest, I do not understand why the filtering is necessary while actually sys-devel/gcc[pie] claims that pie should be added automatically, anyway: It is not the case that all the mentioned packages do add -no-pie internally.

mv,mv wrote:Yes, for several packages they need to be filtered.Cuong Nguyen wrote:-pie -fPIE flags break several packages
However, you always catch this during compile time.
To be honest, I do not understand why the filtering is necessary while actually sys-devel/gcc[pie] claims that pie should be added automatically, anyway: It is not the case that all the mentioned packages do add -no-pie internally.

How to define a core set to start with? Should I build a neutral, cpu independent toolchain in binary and use it to compile all other packages? like march=x86-64 mtune=generic.NeddySeagoon wrote:Cuong Nguyen,
There is a half way house too. You build a core set of packages that will suit all the systems.
This core set is build once, install everywhere.
Where performance matters (if it does), you build the package locally, so it makes best use of the hardware.
That's what you have to decide. I had a lot of instabilities, but that was quite a while ago (perhaps gcc-4). The situation might have been improved, meanwhile.Cuong Nguyen wrote:One more question, should I stop using graphite flags?

mv wrote:However, the problem is that these issues usually come up only at runtime, and I have decided that a theoretical slight speed improvement is not worth random segfaults or strange behavior: When it occurs, one has forgotten that the cflags might be the reason. I was hunting such bugs several times and when it turned out once too often that graphite was the reason, I had decided to stop it and evade further trouble.Cuong Nguyen wrote:One more question, should I stop using graphite flags?
That's also a reason why I think it isn't worth the trouble. For -flto there is quite an impressive reduction in disk space, sometimes (e.g. for eix it was(is?) regularly the case that the binary size reduced to 1/3, probably in combination with -fmerge-all-constants or something similar), but for graphite the award is minimal. Perhaps it makes sense to enable graphite selectively for special packages, e.g. gcc, clang, llvm, ffmpeg and some similar multimedia packages which use the processor heavily. So far, I never played with that.Cuong Nguyen wrote:I did not notice any performance improvement though,

Code: Select all
--param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=12288Code: Select all
--param l1-cache-size=32 l1-cache-line-size=64 l2-cache-size=12288AFAIK every option in gcc can be specified in 1 argument:Cuong Nguyen wrote:1. if I use --param in CFLAGS
Code: Select all
--param=l1-cache-size=32I suppose that you have found this directory in portage-env-mv. This directory is accessed by the function mv_epatch from env/scripts/mv_patch. The latter file in turn is sourced by e.g. env/%{CATEGORY}/%{PF}. The advantage is that this works reliably also for packages whose EAPI is too old (so that they do not support /etc/portage/patches) and which do not inherit the eutils (or the recent epatch) eclass so that the epatch and epatch_user commands are not available (there do exist some horrible hacks on some gentoo wiki how to source the latter eclasses manually, but it is much cleaner to provide a local patch function instead.)2. How to use patch files in /etc/portage/env/patches
3. How can I monitor build.log for certain messages like lto flags caused plugins required... warnings so I can stop emerging and adjust flags? I use emerge --keep-going --quiet-build=y so all messages are in background
Code: Select all
watch grep 'plugin.*required' /path/to/build.log
mv, thank you very much for your detailed explanation. I was too lazy to learn how to script ebuild hooks, your portage-bashrc-mv saves me tons of time to do per-package building customization. Now I put all my mods in /etc/portage/package.cflags/local.mv wrote: For a public repository like portage-env-mv, this has the additional advantage that only /etc/portage/env needs to be contained in the repository so that you can checkout the repository directly into your /etc/portage without collisions with your local /etc/portage/patches.