Page MenuHomePhabricator

[AVR][clang] Search for avr-libc in $SYSROOT/avr
ClosedPublic

Authored by mhjacobson on Aug 6 2021, 3:34 PM.

Details

Summary

The paths in PossibleAVRLibcLocations are appended with /lib/ and /include/ to find the binaries and headers, respectively, for avr-libc.

It's common for avr-libc to live at $SYSROOT/avr/{lib,include}/, e.g. when $SYSROOT is, for example, /opt/local/.

Diff Detail

Event Timeline

mhjacobson created this revision.Aug 6 2021, 3:34 PM
mhjacobson requested review of this revision.Aug 6 2021, 3:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 3:34 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I'm also tempted to remove /usr/lib/avr, because these paths make no sense to me: $SYSROOT/usr/lib/avr/lib and $SYSROOT/usr/lib/avr/include.

But I haven't done that here, in case there's some reason those paths do make sense. (Also, the files in clang/test/Driver/Inputs/basic_avr_tree make use of the /usr/lib/avr/{lib,include} structure.)

I'm also tempted to remove /usr/lib/avr, because these paths make no sense to me: $SYSROOT/usr/lib/avr/lib and $SYSROOT/usr/lib/avr/include.

Ah. According to https://reviews.llvm.org/D54334, that was added because that's where Ubuntu installs avr-libc. OK then!

benshi001 accepted this revision.Aug 6 2021, 6:48 PM
This revision is now accepted and ready to land.Aug 6 2021, 6:48 PM
MaskRay added a comment.EditedAug 6 2021, 7:11 PM

I know nearly nothing about AVR, but from avr-gcc a.c '-###' I doubt this is the GCC behavior. GCC's library path is relative to the GCC installation. /usr/lib/gcc/avr/5.4.0/../../../avr/lib

There is a difference between sysroot inferred path and GCC installation inferred path. https://maskray.me/blog/2021-03-28-compiler-driver-and-cross-compilation

This revision was landed with ongoing or failed builds.Aug 6 2021, 7:25 PM
This revision was automatically updated to reflect the committed changes.

I know nearly nothing about AVR, but from avr-gcc a.c '-###' I doubt this is the GCC behavior. GCC's library path is relative to the GCC installation. /usr/lib/gcc/avr/5.4.0/../../../avr/lib

There is a difference between sysroot inferred path and GCC installation inferred path. https://maskray.me/blog/2021-03-28-compiler-driver-and-cross-compilation

Wow, nice write-up! I'll have to spend some more time to digest it fully.

At first glance, I think you're right: avr-gcc does expect avr-libc to be relative to itself. That seems slightly weird to me (since avr-libc is technically separate from GCC), but OK.

clang's driver certainly searches for libgcc and avr-libc separately. I guess you're saying it shouldn't?

Obviously the separate searching isn't something introduced here, so (unless you object) I'll file a bug report about it.

MaskRay added a comment.EditedAug 6 2021, 7:37 PM

@benshi001 This was prematurely committed. It has no test and has apparent unaddressed issue. (I revamped many parts in the Linux/Gnu search paths so am quite confident about my observation.)

At first glance, I think you're right: avr-gcc does expect avr-libc to be relative to itself. That seems slightly weird to me (since avr-libc is technically separate from GCC), but OK.

OK, after looking at the GCC source, I see there's nothing specific to avr-libc. It's just that GCC basically tries to look in $PREFIX/[machine/]lib, where $PREFIX is actually the path to GCC, dot-dotted up to where it thinks the prefix lives, to allow for the possibility that the whole prefix was relocated.

So, @MaskRay, correct me if I'm wrong: it seems like you're suggesting that we use something derived from the GCCInstallationDetector to find libc? Is there another platform's driver I can look at as an example?

@benshi001 This was prematurely committed. It has no test and has apparent unaddressed issue. (I revamped many parts in the Linux/Gnu search paths so am quite confident about my observation.)

I'm working on a test now, and I'll submit a follow-up patch adding it, if that's OK.

At first glance, I think you're right: avr-gcc does expect avr-libc to be relative to itself. That seems slightly weird to me (since avr-libc is technically separate from GCC), but OK.

OK, after looking at the GCC source, I see there's nothing specific to avr-libc. It's just that GCC basically tries to look in $PREFIX/[machine/]lib, where $PREFIX is actually the path to GCC, dot-dotted up to where it thinks the prefix lives, to allow for the possibility that the whole prefix was relocated.

So, @MaskRay, correct me if I'm wrong: it seems like you're suggesting that we use something derived from the GCCInstallationDetector to find libc? Is there another platform's driver I can look at as an example?

I think so. It would be better to search avr-libc relatively from avr-gcc/../../../, and have submit it as https://reviews.llvm.org/D107682.

@mhjacobson, could you please check if it work on your platform? It does work on my ubuntu system.