Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use LFS64 functions on linux/musl #2589

Merged
merged 1 commit into from
Jan 3, 2023
Merged

Do not use LFS64 functions on linux/musl #2589

merged 1 commit into from
Jan 3, 2023

Conversation

kraj
Copy link
Contributor

@kraj kraj commented Dec 30, 2022

On musl, off_t is 64bit always ( even on 32bit platforms ), therefore using LFS64 funcitons is not needed on such platforms. Moreover, musl has stopped providing aliases for these functions [1] which means it wont compile on newer musl systems. Therefore only use it on 32bit glibc/linux platforms and exclude musl like cygwin or OSX

[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
Signed-off-by: Khem Raj raj.khem@gmail.com

On musl, off_t is 64bit always ( even on 32bit platforms ), therefore
using LFS64 funcitons is not needed on such platforms. Moreover, musl
has stopped providing aliases for these functions [1] which means it
wont compile on newer musl systems. Therefore only use it on 32bit
glibc/linux platforms and exclude musl like cygwin or OSX

[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
Signed-off-by: Khem Raj <raj.khem@gmail.com>
// 64 bits(but not in osx or cygwin, where fstat64 is deprecated)
# if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
// 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated)
# if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
Copy link
Owner

Choose a reason for hiding this comment

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

Better check for some kind of musl specifc macro to detect it. Who knows what it may break checking GLIBC for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glibc defined the macro long time ago and it won’t go away ever however musl does not define any libc identifying macros intentionally

Copy link
Owner

@gabime gabime Dec 31, 2022

Choose a reason for hiding this comment

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

This would affect any other libc vendors that dont define GLIBC .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its already checking for linux, which limits the C library choices. Glibc and uclibc already define GLIBC, third option is musl and another option is bionic/android which would be similar to musl, if needed it can be controlled via android define. Do you have any other combination that spdlog supports on linux ?

Copy link
Owner

Choose a reason for hiding this comment

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

There is no specific combination, but this is bit dangerous. Who knows what libc impl this would break. According to this, there are at least 11. Makes much more sense to check for musl if this is a musl fix

Copy link
Contributor Author

@kraj kraj Dec 31, 2022

Choose a reason for hiding this comment

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

Let me put it differently. What this code does currently is glibc specific, LFS64 functions are not posix defined. It’s not Linux specific. So perhaps making the check to also look for glibc is the right thing here

Copy link
Owner

@gabime gabime Jan 3, 2023

Choose a reason for hiding this comment

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

That’s probably right. I am even thinking to remove the use of fstat64() entirely, since it seems that in 64 bit platforms the regular fstat() already returns the 64 version of off_t (including android bionic). Could you please check this assumption @kraj ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. On 64bit linux and AFAICT BSDs and OSX off_t is 64bit

@gabime gabime merged commit 287a00d into gabime:v1.x Jan 3, 2023
@gabime
Copy link
Owner

gabime commented Jan 3, 2023

Merged. Thanks @kraj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants