ajtowns
commented at 8:25 AM on November 9, 2020:
contributor
When bitcoin is checked out in two directories (eg via git worktree) object files between the two will differ due to the full path being included in the debug section. -fdebug-prefix-map is used to replace this with "." to avoid this unnecessary difference and allow ccache to share objects between worktrees (provided the source and compile options are the same).
Also provide -fmacro-prefix-map if supported so that the working dir is not encoded in __FILE__ macros.
ajtowns added the label Build system on Nov 9, 2020
laanwj
commented at 8:43 AM on November 9, 2020:
member
TIL.
Concept ACK.
Something could be said for also passing it in the non-debug case. After all, even without explicit debug information enabled, gcc adds some level of basic debug information like symbols, and yes this includes file paths:
$ strings -a src/bitcoind | grep /home/$USER|wc -l
1524
Not all of these come from debug information though! They may also be from __FILE__ macro. Is there a flag for that? E.g.:
allow ccache to share objects between worktrees (provided the source and compile options are the same).
This sound sensible on first glance but does make me wonder how ccache "knows" this? When can it assume objects are portable between build directories. Does it explicitly pay attention to this flag?
Edit: also mind that if you're doing depends builds (I didn't in my examples above), things become even more complicated because the depends are also compiled from specific directories inside the specific work tree.
laanwj
commented at 8:54 AM on November 9, 2020:
member
They may also be from FILE macro. Is there a flag for that? E.g.:
FWIW there's, starting with GCC 8, also -fmacro-prefix-map=old=new. Go wild :slightly_smiling_face:
sipa
commented at 8:58 AM on November 9, 2020:
member
And also a -ffile-prefix-map=old=new, apparently.
ajtowns
commented at 9:58 AM on November 9, 2020:
contributor
This sound sensible on first glance but does make me wonder how ccache "knows" this? When can it assume objects are portable between build directories. Does it explicitly pay attention to this flag?
Not all of these come from debug information though! They may also be from __FILE__ macro.
Ah, gcc and clang are both giving me relative paths for __FILE__ even without any special options.
also mind that if you're doing depends builds (I didn't in my examples above), things become even more complicated ..
This doesn't pass the options through to even the in-tree submodules, so univalue and secp will continue getting the absolute path encoded; they don't take much time/space to compile though, so I figure that's okay.
And also a -ffile-prefix-map=old=new, apparently.
I think clang supports -fdebug-prefix-map but not macro or file so I think it makes sense to just do debug and macro independently.
ajtowns force-pushed on Nov 9, 2020
ajtowns force-pushed on Nov 9, 2020
ajtowns
commented at 10:13 AM on November 9, 2020:
contributor
Added -fmacro-prefix-map and made them conditional on ccache being enabled.
ajtowns renamed this: configure: Support -fdebug-prefix-map configure: Support -fdebug-prefix-map and -fmacro-prefix-map on Nov 9, 2020
configure: Support -f{debug,macro}-prefix-map
When bitcoin is checked out in two directories (eg via git worktree)
object files between the two will differ due to the full path being
included in the debug section. -fdebug-prefix-map is used to replace
this with "." to avoid this unnecessary difference and allow ccache to
share objects between worktrees (provided the source and compile options
are the same).
Also provide -fmacro-prefix-map if supported so that the working dir is
not encoded in __FILE__ macros.
7abac98d3e
ajtowns force-pushed on Nov 9, 2020
laanwj
commented at 10:36 AM on November 9, 2020:
member
Ah, gcc and clang are both giving me relative paths for FILE even without any special options.
It depends on what is passed to the compiler. I think for the macros they embed those paths literally. For the DWARF information, the absolute path is used (and there's also header paths, not just compilation unit paths). In any case there seems variance between systems and compilers here. As always…
Added -fmacro-prefix-map and made them conditional on ccache being enabled
Concept ACK on making it depend on --enable-ccache.
practicalswift
commented at 12:02 PM on November 9, 2020:
contributor
Concept ACK: path name leaking should be avoided
ajtowns
commented at 6:21 AM on January 10, 2021:
contributor
Anyone want to bump their acks from concept to reality?
practicalswift
commented at 3:55 PM on January 10, 2021:
contributor
fanquake
commented at 7:42 AM on March 24, 2021:
member
Concept ACK. Will test.
I think clang supports -fdebug-prefix-map but not macro or file so I think it makes sense to just do debug and macro independently.
There's:
-fdebug-prefix-map=OLD=NEW GCC (forever) & Clang 3.8+
-fmacro-prefix-map=OLD=NEW GCC 8+ Clang 10+
and also
-ffile-prefix-map=OLD=NEW GCC 8+ & Clang 10+.
which is just equal to -fdebug-prefix-map -fmacro-prefix-map; so setting both seems best for now. Could add a note that what were are doing is the equivalent to -ffile-prefix-map.
Looks like there's even a BUILD_PATH_PREFIX_MAP environment var under discussion.
fanquake approved
fanquake
commented at 11:56 AM on April 20, 2021:
member
ACK7abac98d3e3c1bc8ad66cb5c05184b9c5cc674d5
Tested this using git worktrees and ccache. Doing something like:
# master
DIR A
./autogen.sh && ./configure --without-gui
gmake -C src/bitcoind
ccache --zero-stats
DIR B (git worktree)
./autogen.sh && ./configure --without-gui
gmake src/bitcoind -j8
hit rate:
cache miss 217
cache hit rate 0.00 %
# cleanup, remove worktree, nuke ccache
[#20353](/github-metadata-backup-bitcoin-bitcoin/20353/)
DIR A
./autogen.sh && ./configure --without-gui
gmake -C src/bitcoind
ccache --zero-stats
DIR B (git worktree different again)
./autogen.sh && ./configure --without-gui
gmake src/bitcoind -j8
hit rate:
cache miss 0
cache hit rate 100.00 %
Also tested when building using depends, configured via: ./autogen.sh && CONFIG_SITE=bitcoin/depends/x86_64-apple-darwin19.6.0/share/config.site ./configure
MarcoFalke
commented at 12:02 PM on April 20, 2021:
member
Wouldn't it be easier to set CCACHE_NOHASHDIR=1? Sure, the paths in the debug information might be wrong, but does it matter?
ajtowns
commented at 12:37 PM on April 20, 2021:
contributor
Wouldn't it be easier to set CCACHE_NOHASHDIR=1? Sure, the paths in the debug information might be wrong, but does it matter?
AIUI, if the __FILE__ macro doesn't match (ie what macro-prefix-map fixes), the preprocessed input to ccache will be different, causing ccache misses. debug-prefix-map fixes the deug info paths, and then triggers ccache to automatically set CCACHE_NOHASHDIR=1. So these seems like the "proper" way to do it and it's not a big patch, so setting CCACHE_NOHASHDIR=1 doesn't seem that much easier?
MarcoFalke
commented at 7:02 PM on April 20, 2021:
member
Sure, just wanted to ask because the discussion didn't mention CCACHE_NOHASHDIR at all.
fanquake merged this on Apr 21, 2021
fanquake closed this on Apr 21, 2021
sidhujag referenced this in commit 96346b8092 on Apr 21, 2021
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:54 UTC