This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Detect libstdc++ include paths for native gcc (-m32 and -m64) on Debian i386
ClosedPublic

Authored by MaskRay on Apr 3 2021, 9:28 PM.

Details

Summary

Take gcc-8 on Debian i386 as an example. The target-specific libstdc++ search
path (GPLUSPLUS_TOOL_INCLUDE_DIR) uses the multiarch name i386-linux-gnu,
instead of the triple of the GCC installation i686-linux-gnu (the directory
under usr/lib/gcc/):

/usr/include/c++/8
/usr/include/i386-linux-gnu/c++/8
/usr/include/c++/8/backward

Clang currently detects /usr/lib/gcc/i686-linux-gnu/8/../../../include/i686-linux-gnu/c++/8.
This patch changes the second i686-linux-gnu to i386-linux-gnu so that
/usr/include/i386-linux-gnu/c++/8 can be found.

Fix PR49827 - this was somehow regressed by my previous libstdc++ include path
cleanups and fixes for gcc-cross, but it seems that the paths were never properly tested before.

Diff Detail

Event Timeline

MaskRay requested review of this revision.Apr 3 2021, 9:28 PM
MaskRay created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2021, 9:28 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MaskRay updated this revision to Diff 335127.Apr 3 2021, 9:54 PM

git add two .keep files

MaskRay added a comment.EditedApr 4 2021, 12:18 AM

From an upstream multiarch build of gcc, the libstdc++ search paths are

/tmp/opt/gcc-debug/lib/gcc/x86_64-pc-linux-gnu/11.0.1/../../../../include/c++/11.0.1
/tmp/opt/gcc-debug/lib/gcc/x86_64-pc-linux-gnu/11.0.1/../../../../include/c++/11.0.1/x86_64-pc-linux-gnu
/tmp/opt/gcc-debug/lib/gcc/x86_64-pc-linux-gnu/11.0.1/../../../../include/c++/11.0.1/backward

(this is similar to cross gcc on Debian, except that cross gcc usually uses ../../../../$triple/include/c++/$v)

If you specify --target=x86_64-linux-gnu and install it to /usr, the paths will become.

/usr/include/c++/11.0.1
/usr/include/c++/11.0.1/x86_64-linux-gnu  # for i686-linux-gnu this should be /usr/include/c++/11.0.1/i686-linux-gnu (i686 instead of i386)
/usr/include/c++/11.0.1/backward

If Debian can drop the incdir patch for native gcc, it can reduce some maintenance burden and clang driver can still detect the libstdc++ search paths

sylvestre.ledru accepted this revision.Apr 4 2021, 9:21 AM
sylvestre.ledru added a subscriber: doko.

Many thanks. it fixed my issues!

/usr/include/i386-linux-gnu/c++/8 is indeed much nicer :)

Thanks for all your hard work on fixing the header detection. it was indeed too complex!

And, thanks for asking for review ;)

About the g++-multiarch-incdir.diff, I cced the gcc maintainer!

This revision is now accepted and ready to land.Apr 4 2021, 9:21 AM