This is an archive of the discontinued LLVM Phabricator instance.

Fix libcxx build on 32bit architectures with 64bit time_t defaults e.g. riscv32
ClosedPublic

Authored by ldionne on Aug 2 2020, 10:18 AM.

Details

Summary

RISCV glibc has decided to use 64bit time_t from get go unlike
other 32bit architecture, therefore, aliasing NR_futex to
NR_futex_time64 helps avoid the below errors on rv32

Diff Detail

Event Timeline

raj.khem created this revision.Aug 2 2020, 10:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2020, 10:18 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
raj.khem requested review of this revision.Aug 2 2020, 10:18 AM
raj.khem updated this revision to Diff 282463.Aug 2 2020, 10:39 AM

Fix formatting errors

ldionne requested changes to this revision.Aug 3 2020, 8:26 AM
ldionne added a subscriber: ldionne.
ldionne added inline comments.
libcxx/src/atomic.cpp
18

I'm not sure I understand -- libc++ doesn't use __NR_futex anywhere. Can you explain how this fix works?

This revision now requires changes to proceed.Aug 3 2020, 8:26 AM
raj.khem added inline comments.Aug 3 2020, 10:28 AM
libcxx/src/atomic.cpp
18

libc++ does use SYS_futex, which it expects from system C library, in glibc (/usr/include/bits/syscall.h defines it in terms of of NR_futex) rv32 is using 64bit time_t from get go unlike other 32bit architectures in glibc, therefore it wont have NR_futex defined but just NR_futex_time64, this aliases it to NR_futex so that SYS_futex is then defined for rv32

I think this makes sense, but I'll let the #libc reviewers actually review/approve this.

libcxx/src/atomic.cpp
18

I suggest adding a comment here describing this situation.

apazos added a subscriber: apazos.Sep 17 2020, 8:27 AM

Can you clarify on the errors you are talking about? Are you building LLVM libc++with glibc?
I have been building LLVM libc++ with MUSl and I do not see a build issue.

I suppose that an alternative to this implementation might be to tweak the place of use of __NR_futex, like is done in [1]. Arguably that's cleaner. Or, in the place where you're currently checking for riscv32, check for the case where __NR_futex_ isn't defined but __NR_futex_time64 is, and #define the former in terms of the latter.

[1]: https://sourceware.org/legacy-ml/libc-alpha/2020-01/msg00686.html

raj.khem updated this revision to Diff 305331.Nov 14 2020, 2:50 PM

this revision is not riscv32 specific. Let me know if this is ok

Can you clarify on the errors you are talking about? Are you building LLVM libc++with glibc?
I have been building LLVM libc++ with MUSl and I do not see a build issue.

the errors are not musl specific, but when building for riscv32 target on glibc

raj.khem updated this revision to Diff 305332.Nov 14 2020, 2:56 PM

Add comments in source

raj.khem marked 2 inline comments as done.Nov 14 2020, 2:58 PM
raj.khem retitled this revision from Fix libcxx build on riscv32 to Fix libcxx build on 32bit architectures with 64bit time_t defaults e.g. riscv32.
raj.khem updated this revision to Diff 305585.Nov 16 2020, 1:36 PM

it should have been after including syscall.h

ldionne requested changes to this revision.Nov 17 2020, 12:40 PM

I don't understand why this has its place in libc++. Shouldn't this be in glibc instead?

This revision now requires changes to proceed.Nov 17 2020, 12:40 PM

I don't understand why this has its place in libc++. Shouldn't this be in glibc instead?

SYS_futex is not a universal syscall name for all architectures as explained in the comment, and libc++ is assuming that incorrectly. hope that helps

ldionne commandeered this revision.Feb 3 2021, 1:59 PM
ldionne edited reviewers, added: raj.khem; removed: ldionne.
ldionne updated this revision to Diff 321223.Feb 3 2021, 2:06 PM

Rebase onto main and trigger CI.

@luismarques Does this still look good to you? If so, I'll commit once CI is green.

@luismarques Does this still look good to you? If so, I'll commit once CI is green.

LGTM.
I think the current target-independent implementation of the patch really is the way to go, so this now looks even better. Thanks!

luismarques accepted this revision.Feb 4 2021, 8:30 AM
This revision was not accepted when it landed; it landed in state Needs Review.Feb 4 2021, 8:39 AM
This revision was automatically updated to reflect the committed changes.

Can we get this on clang 12 release branch as well ?

Can we get this on clang 12 release branch as well ?

See https://reviews.llvm.org/D96062.