Skip to content

configure: Support -fdebug-prefix-map and -fmacro-prefix-map - #20353

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
ajtowns:202011-ccache-debug-prefix
Apr 21, 2021
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
ajtowns:202011-ccache-debug-prefix

Conversation

@ajtowns

@ajtowns ajtowns commented Nov 9, 2020 •

Copy link
Copy Markdown
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.

@laanwj

laanwj commented Nov 9, 2020 •

Copy link
Copy Markdown
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.:

$ objdump --dwarf=info src/bitcoind|grep DW_AT_comp_dir
    <1a>   DW_AT_comp_dir    : (indirect string, offset: 0x9f): /home/…/projects/bitcoin/bitcoin/build/src
    <282c9>   DW_AT_comp_dir    : (indirect string, offset: 0x9f): /home/…/projects/bitcoin/bitcoin/build/src
    <1f2597>   DW_AT_comp_dir    : (indirect string, offset: 0x9f): /home/…/projects/bitcoin/bitcoin/build/src
    <263930>   DW_AT_comp_dir    : (indirect string, offset: 0x9f): /home/…/projects/bitcoin/bitcoin/build/src
    <399a44>   DW_AT_comp_dir    : (indirect string, offset: 0x9f): /home/…/projects/bitcoin/bitcoin/build/src
$ strip src/bitcoind
$ objdump --dwarf=info src/bitcoind|grep DW_AT_comp_dir
$ strings -a src/bitcoind | grep /home/$USER|wc -l
134

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

laanwj commented Nov 9, 2020 •

Copy link
Copy Markdown
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 🙂

@sipa

sipa commented Nov 9, 2020

Copy link
Copy Markdown
Member

And also a -ffile-prefix-map=old=new, apparently.

@ajtowns

ajtowns commented Nov 9, 2020

Copy link
Copy Markdown
Contributor Author

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?

Yeah:

$ strings /usr/bin/ccache | grep .-map
-fdebug-prefix-map=
-ffile-prefix-map=
-fmacro-prefix-map=

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
ajtowns force-pushed the 202011-ccache-debug-prefix branch 2 times, most recently from 9ff4e40 to 71f2d81 Compare November 9, 2020 10:13
@ajtowns

ajtowns commented Nov 9, 2020 •

Copy link
Copy Markdown
Contributor Author

Added -fmacro-prefix-map and made them conditional on ccache being enabled.

@ajtowns ajtowns changed the title configure: Support -fdebug-prefix-map configure: Support -fdebug-prefix-map and -fmacro-prefix-map Nov 9, 2020
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
ajtowns force-pushed the 202011-ccache-debug-prefix branch from 71f2d81 to 7abac98 Compare November 9, 2020 10:16
@laanwj

laanwj commented Nov 9, 2020 •

Copy link
Copy Markdown
Member

Yeah:
$ strings /usr/bin/ccache | grep .-map
-fdebug-prefix-map=
-ffile-prefix-map=
-fmacro-prefix-map=

Thanks, good to know.

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

Copy link
Copy Markdown
Contributor

Concept ACK: path name leaking should be avoided

@ajtowns

ajtowns commented Jan 10, 2021

Copy link
Copy Markdown
Contributor Author

Anyone want to bump their acks from concept to reality?

@practicalswift

Copy link
Copy Markdown
Contributor

cr ACK 7abac98: patch looks correct

@fanquake fanquake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fanquake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7abac98

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
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

@maflcko

maflcko commented Apr 20, 2021

Copy link
Copy Markdown
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

ajtowns commented Apr 20, 2021 •

Copy link
Copy Markdown
Contributor Author

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?

@maflcko

maflcko commented Apr 20, 2021

Copy link
Copy Markdown
Member

Sure, just wanted to ask because the discussion didn't mention CCACHE_NOHASHDIR at all.

@fanquake
fanquake merged commit e507acb into bitcoin:master Apr 21, 2021
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…o-prefix-map

7abac98 configure: Support -f{debug,macro}-prefix-map (Anthony Towns)

Pull request description:

  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.

ACKs for top commit:
  practicalswift:
    cr ACK 7abac98: patch looks correct
  fanquake:
    ACK 7abac98

Tree-SHA512: b6a37c1728ec3b2e552f244da0e66db113c1e7662c7ac502e12ff466f3dbfbfefae12695ca135137c50dbb1c4c5d84059116c0cd09b391a17466dc77b8726679
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 16, 2021
…o-prefix-map

7abac98 configure: Support -f{debug,macro}-prefix-map (Anthony Towns)

Pull request description:

  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.

ACKs for top commit:
  practicalswift:
    cr ACK 7abac98: patch looks correct
  fanquake:
    ACK 7abac98

Tree-SHA512: b6a37c1728ec3b2e552f244da0e66db113c1e7662c7ac502e12ff466f3dbfbfefae12695ca135137c50dbb1c4c5d84059116c0cd09b391a17466dc77b8726679
fanquake added a commit that referenced this pull request Oct 11, 2021
0bc666b doc: add info for debugging with relative paths (S3RK)
a8b515c configure: keep relative paths in debug info (S3RK)

Pull request description:

  This is a follow-up for #20353 that fixes #21885

  It also adds a small section to assist debugging without absolute paths in debug info.

ACKs for top commit:
  kallewoof:
    Tested ACK 0bc666b
  Zero-1729:
    Light crACK 0bc666b

Tree-SHA512: d4b75183c3d3a0f59fe786841fb230581de87f6fe04cf7224e4b89c520d45513ba729d4ad8c0e62dd1dbaaa7a25741f04d036bc047f92842e76c9cc31ea47fb2
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 3, 2022
0bc666b doc: add info for debugging with relative paths (S3RK)
a8b515c configure: keep relative paths in debug info (S3RK)

Pull request description:

  This is a follow-up for bitcoin#20353 that fixes bitcoin#21885

  It also adds a small section to assist debugging without absolute paths in debug info.

ACKs for top commit:
  kallewoof:
    Tested ACK 0bc666b
  Zero-1729:
    Light crACK 0bc666b

Tree-SHA512: d4b75183c3d3a0f59fe786841fb230581de87f6fe04cf7224e4b89c520d45513ba729d4ad8c0e62dd1dbaaa7a25741f04d036bc047f92842e76c9cc31ea47fb2
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 9, 2022
…o-prefix-map

7abac98 configure: Support -f{debug,macro}-prefix-map (Anthony Towns)

Pull request description:

  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.

ACKs for top commit:
  practicalswift:
    cr ACK 7abac98: patch looks correct
  fanquake:
    ACK 7abac98

Tree-SHA512: b6a37c1728ec3b2e552f244da0e66db113c1e7662c7ac502e12ff466f3dbfbfefae12695ca135137c50dbb1c4c5d84059116c0cd09b391a17466dc77b8726679
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 9, 2022
0bc666b doc: add info for debugging with relative paths (S3RK)
a8b515c configure: keep relative paths in debug info (S3RK)

Pull request description:

  This is a follow-up for bitcoin#20353 that fixes bitcoin#21885

  It also adds a small section to assist debugging without absolute paths in debug info.

ACKs for top commit:
  kallewoof:
    Tested ACK 0bc666b
  Zero-1729:
    Light crACK 0bc666b

Tree-SHA512: d4b75183c3d3a0f59fe786841fb230581de87f6fe04cf7224e4b89c520d45513ba729d4ad8c0e62dd1dbaaa7a25741f04d036bc047f92842e76c9cc31ea47fb2
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants