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

<strings.h> ffs probably used to work by accident on x86 #439

Closed
enh opened this issue Jun 29, 2017 · 2 comments
Closed

<strings.h> ffs probably used to work by accident on x86 #439

enh opened this issue Jun 29, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@enh
Copy link
Contributor

enh commented Jun 29, 2017

we had an internal report of someone having trouble building some ffs-using code for x86 after they upgraded to r15b. i suspect this was because of the switch to unified headers. in the past, strings.h used to declare ffs for all platforms at all API levels. in the more correct unified headers, there's no such declaration for x86 before API 18.

but --- i think as long as there was a declaration the compiler will have just said "ffs? i know ffs!" and inlined __builtin_ffs and not had any problem at link-time because it wasn't actually adding a reference to the missing symbol.

i think we should probably add a <android/legacy_strings_inlines.h> with a static inline that just calls __builtin_ffs (which is all the libc ffs is anyway).

@enh enh self-assigned this Jun 30, 2017
@enh
Copy link
Contributor Author

enh commented Jun 30, 2017

hubot pushed a commit to aosp-mirror/platform_bionic that referenced this issue Jul 10, 2017
<strings.h>'s ffs used to work by accident. In the past, <strings.h> used
to incorrectly declare ffs for all platforms at all API levels. In the
unified headers, there's no such declaration for x86 before API 18 (which
makes sense, because that function was missing on x86 until then).

But as long as there was a declaration for ffs, the compiler just inlined
__builtin_ffs. There was no problem at link time because the compiler didn't
actually add a reference to the missing ffs symbol.

Restore the old behavior by manually instructing the compiler to inline its
builtin in these cases.

Bug: android/ndk#439
Test: built new NDK 'ffs' test
Change-Id: I840e99f237c86f7cb028a0f67aaa8c6ff3eda245
@enh
Copy link
Contributor Author

enh commented Jul 18, 2017

danalbert cherrypicked this for r15c, so marking closed.

@enh enh closed this as completed Jul 18, 2017
@enh enh added this to the r15c milestone Jul 18, 2017
@enh enh added the headers label Jul 18, 2017
@enh enh reopened this Jul 18, 2017
@enh enh assigned DanAlbert and unassigned enh Jul 18, 2017
miodragdinic pushed a commit to MIPS/ndk that referenced this issue Apr 17, 2018
This test requires <android/legacy_strings_inlines.h>.

Bug: android/ndk#439
Test: ./run_tests.py --filter ffs --rebuild --toolchain clang --ndk /usr/local/google/android-ndk-hacked
Change-Id: I2e6ee1daeca626e0ba739374f4b662ac61438a63
sepehrst pushed a commit to spsforks/android-bionic-libc that referenced this issue Apr 22, 2024
<strings.h>'s ffs used to work by accident. In the past, <strings.h> used
to incorrectly declare ffs for all platforms at all API levels. In the
unified headers, there's no such declaration for x86 before API 18 (which
makes sense, because that function was missing on x86 until then).

But as long as there was a declaration for ffs, the compiler just inlined
__builtin_ffs. There was no problem at link time because the compiler didn't
actually add a reference to the missing ffs symbol.

Restore the old behavior by manually instructing the compiler to inline its
builtin in these cases.

Bug: android/ndk#439
Test: built new NDK 'ffs' test
Change-Id: I840e99f237c86f7cb028a0f67aaa8c6ff3eda245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants