Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 733824 - /etc/portage/package.env is ignored for CFLAGS and CXXFLAGS
Summary: /etc/portage/package.env is ignored for CFLAGS and CXXFLAGS
Status: RESOLVED WORKSFORME
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-24 23:48 UTC by Martin
Modified: 2022-06-28 21:26 UTC (History)
3 users (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 Martin 2020-07-24 23:48:41 UTC
/etc/portage/package.env is ignored:


# ls /etc/portage/env
O2-cflags

# cat /etc/portage/env/O2-cflags 
CFLAGS="-march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong"
CXXFLAGS="${CFLAGS}"

# cat /etc/portage/package.env
media-libs/libpano13 O2-cflags

# egrep '^C(XX)?FLAGS' /etc/portage/make.conf
CFLAGS="-march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong"
CXXFLAGS="${CFLAGS}"


Expected result is that:

# emerge -vD1 media-libs/libpano13

uses "-O2"...

Actual result is:

Options used to compile and link:
  PREFIX         = /usr
  VERSION        = 2.9.19
  CC             = x86_64-pc-linux-gnu-gcc
  CFLAGS         = -march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong
  CPPFLAGS       = 
  DEFS           = -DHAVE_CONFIG_H
  LDFLAGS        = -Wl,-O1 -Wl,--as-needed
  LIBS           = -lm
  CXX            = 
  CXXFLAGS       = -march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong



What should be set to override CFLAGS and CXXFLAGS for this one package?

Thanks,
Martin
Comment 1 Martin 2020-07-24 23:49:31 UTC
Is this a variation of:

https://bugs.gentoo.org/463964

?

Thanks,
Martin
Comment 2 Martin 2022-06-25 18:34:00 UTC
Bump.

This is still a bug, and it is a for various (all?) packages.

Recent examples include for webkit, libreoffice, thunderbird, and firefox.

This is now irksome for the present compile flags problems for those packages. (At least for my old CPU and my preference for running compiles with "-Os"...)


Is package.env still in use in Portage?

Thanks,
Martin
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-25 18:37:39 UTC
This does not match my experience at all.

This is a very commonly used feature (and I use it _all the time_). There's something more going on here?
Comment 4 Ionen Wolkens gentoo-dev 2022-06-25 19:32:19 UTC
If you change your CFLAGS in make.conf, do they get used? Just wondering if these CFLAGS are coming from somewhere else (e.g. the environment, as it takes priority over both make.conf and package.env).

And you're not using a /etc/portage/bashrc, right?

Using the files/settings you've shown as-is, package.env's flags work for me with libpano13 (-Os is replaced and it doesn't fail to build)
Comment 5 Martin 2022-06-28 15:07:27 UTC
(In reply to Ionen Wolkens from comment #4)
> If you change your CFLAGS in make.conf, do they get used? Just wondering if
> these CFLAGS are coming from somewhere else (e.g. the environment, as it
> takes priority over both make.conf and package.env).

The flags as set in "/etc/portage/make.conf" are the ones seen for the actual emerge.


> And you're not using a /etc/portage/bashrc, right?

# ls -lh /etc/portage/bashrc
ls: cannot access '/etc/portage/bashrc': No such file or directory


> Using the files/settings you've shown as-is, package.env's flags work for me
> with libpano13 (-Os is replaced and it doesn't fail to build)

Trying just now gives (same env settings):

# emerge -1v '=media-libs/libpano13-2.9.20-r1' |& tee emerge-1v.log

These are the packages that would be merged, in order:

Calculating dependencies  .... done!
[ebuild  N     ] media-libs/libpano13-2.9.20-r1:0/3::gentoo  USE="-java -static-libs" 3,481 KiB

Total: 1 package (1 new), Size of downloads: 3,481 KiB

>>> Verifying ebuild manifests


>>> Emerging (1 of 1) media-libs/libpano13-2.9.20-r1::gentoo
>>> Downloading 'rsync://mirror.bytemark.co.uk/gentoo/distfiles/32/libpano13-2.9.20.tar.gz' ...

... configure: creating ./config.status
config.status: creating Makefile
config.status: creating build/Makefile
config.status: creating build/win32/Makefile
config.status: creating doc/Makefile
config.status: creating m4/Makefile
config.status: creating tools/Makefile
config.status: creating tests/Makefile
config.status: creating tests/simpleStitch/Makefile
config.status: creating tests/simpleTiff16/Makefile
config.status: creating tests/simpleStitch/reference/Makefile
config.status: creating tests/simpleTiff16/reference/Makefile
config.status: creating tests/simpleTiff2psd/reference/Makefile
config.status: creating tests/simpleTiff2psd/tests/Makefile
config.status: creating tests/simpleTiff2psd/Makefile
config.status: creating man/Makefile
config.status: creating libpano13.pc
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

libpano is configured as follows. Please verify that this configuration
matches your expectations.

Host system type : x86_64-pc-linux-gnu

                  Option                        Value
-------------------------------------------------------------------------
Shared libraries  --enable-shared=yes          
Static libraries  --enable-static=no          
JPEG              --with-jpeg=          have_jpeg = yes
PNG               --with-png=            have_png  = yes
TIFF              --with-tiff=          have_tiff = yes
ZLIB              --with-zlib=          have_zlib = yes
JAVA              --with-java=no          have_java = no

Options used to compile and link:
  PREFIX         = /usr
  VERSION        = 2.9.20
  CC             = x86_64-pc-linux-gnu-gcc
  CFLAGS         = -march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong
  CPPFLAGS       = 
  DEFS           = -DHAVE_CONFIG_H
  LDFLAGS        = -Wl,-O1 -Wl,--as-needed
  LIBS           = -lm
  CXX            = 
  CXXFLAGS       = -march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong
  JPEG_FLAGS     = -DHasJPEG
  LIB_JPEG       = -ljpeg
  PNG_FLAGS      = -DHasPNG
  LIB_PNG        = -lpng
  TIFF_FLAGS     = -DHasTIFF
  LIB_TIFF       = -ltiff
  ZLIB_FLAGS     = -DHasZLIB
  LIB_ZLIB       = -lz
  JAVA_FLAGS     = 
  ENDIAN_FLAG    = 
>>> Source configured.
>>> Compiling source in /var/tmp/portage/media-libs/libpano13-2.9.20-r1/work/libpano13-2.9.20 ...


Note the "CFLAGS         = -march=native -mtune=native -Os ..." that is from /etc/portage/make.conf


fyi:

# ls -lh /etc/portage/package.env
-rw-r--r-- 1 root root 228 Jun 28 15:52 /etc/portage/package.env

# ls -lhd /etc/portage
drwxr-xr-x 9 root root 3.5K Jun 28 15:57 /etc/portage


package.env is also ignored for emerge with llvm clang/rust.


How best to debug this one?

Thanks,
Martin
Comment 6 Martin 2022-06-28 15:16:55 UTC
(In reply to Ionen Wolkens from comment #4)
> If you change your CFLAGS in make.conf, do they get used?...

Changing just /etc/portage/make.conf:

# egrep '^C(XX)?FLAGS' /etc/portage/make.conf
CFLAGS="-march=amdfam10 -mtune=amdfam10 -m3dnow -mabm -mcx16 -mfxsr -mlzcnt -mmmx -mpopcnt -mprfchw -msahf -msse -msse2 -msse3 -msse4a --param=l1-cache-line-size=64 --param=l1-cache-size=64 --param=l2-cache-size=512 -Os -fomit-frame-pointer -pipe -fstack-protector-strong"
CXXFLAGS="${CFLAGS}"


And lo:

# emerge -1v '=media-libs/libpano13-2.9.20-r1' |& tee emerge-1v_amdfam10.log

These are the packages that would be merged, in order:

Calculating dependencies  ... done!
[ebuild  N     ] media-libs/libpano13-2.9.20-r1:0/3::gentoo  USE="-java -static-libs" 0 KiB

Total: 1 package (1 new), Size of downloads: 0 KiB

>>> Verifying ebuild manifests


>>> Emerging (1 of 1) media-libs/libpano13-2.9.20-r1::gentoo ...

... libpano is configured as follows. Please verify that this configuration
matches your expectations.

Host system type : x86_64-pc-linux-gnu

                  Option                        Value
-------------------------------------------------------------------------
Shared libraries  --enable-shared=yes          
Static libraries  --enable-static=no          
JPEG              --with-jpeg=          have_jpeg = yes
PNG               --with-png=            have_png  = yes
TIFF              --with-tiff=          have_tiff = yes
ZLIB              --with-zlib=          have_zlib = yes
JAVA              --with-java=no          have_java = no

Options used to compile and link:
  PREFIX         = /usr
  VERSION        = 2.9.20
  CC             = x86_64-pc-linux-gnu-gcc
  CFLAGS         = -march=amdfam10 -mtune=amdfam10 -m3dnow -mabm -mcx16 -mfxsr -mlzcnt -mmmx -mpopcnt -mprfchw -msahf -msse -msse2 -msse3 -msse4a --param=l1-cache-line-size=64 --param=l1-cache-size=64 --param=l2-cache-size=512 -Os -fomit-frame-pointer -pipe -fstack-protector-strong
  CPPFLAGS       = 
  DEFS           = -DHAVE_CONFIG_H
  LDFLAGS        = -Wl,-O1 -Wl,--as-needed
  LIBS           = -lm
  CXX            = 
  CXXFLAGS       = -march=amdfam10 -mtune=amdfam10 -m3dnow -mabm -mcx16 -mfxsr -mlzcnt -mmmx -mpopcnt -mprfchw -msahf -msse -msse2 -msse3 -msse4a --param=l1-cache-line-size=64 --param=l1-cache-size=64 --param=l2-cache-size=512 -Os -fomit-frame-pointer -pipe -fstack-protector-strong ...


?

Regards,
Martin
Comment 7 Mike Gilbert gentoo-dev 2022-06-28 15:53:18 UTC
Works fine for me:

> % grep CFLAGS /etc/portage/make.conf:
> CFLAGS="-O2 -pipe -march=amdfam10 -frecord-gcc-switches"
> 
> % cat /etc/portage/env/O2-cflags
> CFLAGS="-march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong"
> CXXFLAGS="${CFLAGS}"
> 
> % cat /etc/portage/package.env/libpano13
> media-libs/libpano13 O2-cflags
> 
> % emerge -v1 media-libs/libpano13
> ...
> C               -march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong
Comment 8 Mike Gilbert gentoo-dev 2022-06-28 15:54:05 UTC
Maybe check file permissions on /etc/portage/env and /etc/portage/package.env?
Comment 9 Martin 2022-06-28 16:36:50 UTC
(In reply to Mike Gilbert from comment #8)
> Maybe check file permissions on /etc/portage/env and
> /etc/portage/package.env?

Thanks. Good thought:

# ls -alh /etc/portage
total 91K
drwxr-xr-x   9 root root 3.5K Jun 28 16:12 .
drwxr-xr-x 101 root root 8.0K Jun 28 15:16 ..
drwxr-xr-x   2 root root 3.5K Jun 27 02:41 env
-rwxr-xr-x   1 root root  33K Jun 28 16:12 make.conf
lrwxrwxrwx   1 root root   59 Jun 30  2020 make.profile -> ../../usr/portage/profiles/default/linux/amd64/17.1/desktop
-rw-r--r--   1 root root  15K Jun  2 21:14 package.accept_keywords
-rw-r--r--   1 root root  228 Jun 28 15:52 package.env
-rw-r--r--   1 root root 2.3K Apr 23 18:52 package.license
drwxr-xr-x   2 root root 3.5K Jun 25 17:57 package.mask
drwxr-xr-x   2 root root 3.5K Aug  8  2020 package.unmask
drwxr-xr-x   2 root root 3.5K Jun 28 00:06 package.use
drwxr-xr-x   4 root root 3.5K Feb  9  2021 patches
drwxr-xr-x   2 root root 3.5K Jun  3  2019 repos.conf
drwxr-xr-x   4 root root 3.5K Jan  9  2018 savedconfig

# ls -alh /etc/portage/env
total 9.0K
drwxr-xr-x 2 root root 3.5K Jun 27 02:41 .
drwxr-xr-x 9 root root 3.5K Jun 28 16:12 ..
-rw-r--r-- 1 root root  294 Jun 27 01:41 amdfam10-Os-cflags
-rw-r--r-- 1 root root  116 Jun 23 22:09 generic-Os-cflags
-rw-r--r-- 1 root root  114 Jul 25  2020 O2-cflags
-rw-r--r-- 1 root root  114 Jun  9 01:54 O3-cflags

Regards,
Martin
Comment 10 Martin 2022-06-28 16:46:30 UTC
# chmod +x /etc/portage/env/*

And... Still no effect to have the "O2" replace the make.conf "Os"...


Regards,
Martin
Comment 11 Martin 2022-06-28 16:52:28 UTC
(In reply to Mike Gilbert from comment #7)
> Works fine for me:
> 
> > % grep CFLAGS /etc/portage/make.conf:
> > CFLAGS="-O2 -pipe -march=amdfam10 -frecord-gcc-switches"
> > 
> > % cat /etc/portage/env/O2-cflags
> > CFLAGS="-march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong"
> > CXXFLAGS="${CFLAGS}"
> > 
> > % cat /etc/portage/package.env/libpano13
> > media-libs/libpano13 O2-cflags
> > 
> > % emerge -v1 media-libs/libpano13
> > ...
> > C               -march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong

Try that with "-Os" in /etc/portage/make.conf ?...

Thanks,
Martin
Comment 12 Mike Gilbert gentoo-dev 2022-06-28 17:41:06 UTC
(In reply to Martin from comment #11)
> Try that with "-Os" in /etc/portage/make.conf ?...

That won't make any difference. It's clearly using the flags from package.env, not make.conf.
Comment 13 Mike Gilbert gentoo-dev 2022-06-28 17:42:19 UTC
I'm closing this as WORKSFORME. If you wish to debug this further, maybe drop into #gentoo-portage on Libra.chat IRC.
Comment 14 Martin 2022-06-28 19:36:44 UTC
(In reply to Mike Gilbert from comment #13)
> I'm closing this as WORKSFORME. If you wish to debug this further, maybe
> drop into #gentoo-portage on Libra.chat IRC.

Using your exact same example, yes, that example works for me also.


Now try with the one change in /etc/portage/make.conf to change the "-O2" to instead be "-Os".

# grep CFLAGS /etc/portage/make.conf
CFLAGS="-Os -pipe -march=amdfam10 -frecord-gcc-switches"


The expected result is that the compile succeeds utilizing the "-O2" from /etc/portage/package.env/libpano13

Except, that instead, we still see "-Os" is being used:

# emerge -1v '=media-libs/libpano13-2.9.20-r1' |& tee emerge-1v_libpano13_Os.log
# grep '\-O' emerge-1v_libpano13_Os.log | head -n 4
  CFLAGS         = -Os -pipe -march=amdfam10 -frecord-gcc-switches
  LDFLAGS        = -Wl,-O1 -Wl,--as-needed
  CXXFLAGS       = -Os -pipe -march=amdfam10 -frecord-gcc-switches
/bin/sh ./libtool  --tag=CC   --mode=compile x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I.   -DHasJPEG -DHasPNG -DHasTIFF -DHasZLIB  -D__Ansi__=1      -Os -pipe -march=amdfam10 -frecord-gcc-switches -c -o filter.lo filter.c


?

Regards,
Martin
Comment 15 Martin 2022-06-28 19:44:35 UTC
fyi:

# strace emerge -1v '=media-libs/libpano13-2.9.20-r1' |& tee emerge-1v_libpano13_Os_strace.log

# grep '/etc' emerge-1v_libpano13_Os_strace.log | grep -v 'No such file or directory' | grep 'openat'
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/python-exec/python-exec.conf", O_RDONLY) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/make.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/profile.env", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/repos.conf", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/etc/portage/repos.conf/gentoo.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/repos.conf/layman.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/make.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.use", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/etc/portage/package.license", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.env", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/etc/portage/package.env/libpano13", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.accept_keywords", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.mask", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/etc/portage/package.mask/emerges_fixes", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.unmask", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/etc/portage/package.unmask/flash_player", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/package.unmask/misc_packages:", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/portage/env/O2-cflags", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/etc/profile.env", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/etc/portage/env/O2-cflags", O_RDONLY|O_CLOEXEC) = 7
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 11
openat(AT_FDCWD, "/etc/profile.env", O_RDONLY|O_CLOEXEC) = 7


So... "/etc/portage/env/O2-cflags" looks to be being read, even if the CFLAGS variable is not being honoured.

And just to double check:

# cat "/etc/portage/env/O2-cflags"
CFLAGS="-march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong"
CXXFLAGS="${CFLAGS}"


Will take a look on IRC... Thanks.

Regards,
Martin
Comment 16 Mike Gilbert gentoo-dev 2022-06-28 19:47:22 UTC
Putting -Os in make.conf made no difference here.
Comment 17 Ionen Wolkens gentoo-dev 2022-06-28 20:04:30 UTC
Like mentioned before, I tried exact same as your first example (same files, same -Os, and O2-cflags), and it'd fail to build if it didn't work.. but it did build for me (and did fail if I removed the package.env).

My best guess was that there may be something in the environment overriding these, e.g. `CFLAGS=-Os emerge ...` would ignore both make.conf and package.env, but well... if it's not that then I really have no idea what's special on your system. This works for a lot of people so it sound isolated.
Comment 18 Martin 2022-06-28 21:26:21 UTC
(In reply to Ionen Wolkens from comment #17)
> ...
> My best guess was that there may be something in the environment overriding
> these, e.g. `CFLAGS=-Os emerge ...` would ignore both make.conf and
> package.env...

Thanks for the true revelation...


So... There's no CFLAGS set in /root/.bashrc or anywhere in /etc other than in /etc/portage/...

Yet seen for root:

# echo "$CFLAGS"
-march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong

!!...

root was su-ed from a user... And in ~/.bashrc for that one user includes:

export CFLAGS="-march=native -mtune=native -Os -fomit-frame-pointer -pipe -fstack-protector-strong"
export CXXFLAGS=$CFLAGS


Using for root:

# unset CFLAGS
# unset CXXFLAGS

and henceforth:

emerge, /etc/portage/env and /etc/portage/package.env work as expected:

# emerge -1v '=media-libs/libpano13-2.9.20-r1' |& tee emerge-1v_libpano13_Os_unset-CFLAGS.log

  CFLAGS         = -march=native -mtune=native -O2 -fomit-frame-pointer -pipe -fstack-protector-strong

(That is with -Os set in make.conf and -O2 as set in O2-flags.)


Many thanks for puzzling through that obscurity!

Indeed resolved worksforme.


Regards,
Martin