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

Building a library with ffreestanding flag. #1117

Closed
hanseul1795 opened this issue Nov 4, 2019 · 3 comments
Closed

Building a library with ffreestanding flag. #1117

hanseul1795 opened this issue Nov 4, 2019 · 3 comments
Labels

Comments

@hanseul1795
Copy link

Description

I'm trying a build a library with --ffreestanding flag on Android NDK r19c, and I'm getting use of undeclared identifier "LONG_BIT" error.

I know that (from #352), --ffreestanding

is the cause but it's a requirement for the library.

In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials\Engine\Tools\AndroidBuild\android-ndk-r19c\sources\android\cpufeatures\cpu-features.c:69:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\pthread.h:37:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\time.h:33:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\sys/time.h:37:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\sys/select.h:36:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\signal.h:37:
C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\bits/signal_types.h:65:53: error: use of undeclared identifier 'LONG_BIT'
typedef struct { unsigned long __bits[_KERNEL__NSIG/LONG_BIT]; } sigset64_t;
                                                    ^
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials\Engine\Tools\AndroidBuild\android-ndk-r19c\sources\android\cpufeatures\cpu-features.c:69:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\pthread.h:37:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\time.h:33:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\sys/time.h:37:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\sys/select.h:36:
In file included from C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\signal.h:203:
C:\Users\hanseul.shin\Desktop\PremakeTest\tutorials/Engine/Tools/AndroidBuild/android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\android/legacy_signal_inlines.h:71:33: error: use of undeclared identifier 'LONG_BIT'
  return (int)((local_set[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1);
	.CFLAGS            	+  -m32 -target $NDKToolchainArmTarget$ -march=armv7-a -mfloat-abi=softfp -mcpu=cortex-a9 -mfpu=neon-vfpv4'
                        + ' -ffreestanding -fomit-frame-pointer'
	.Librarian         	= '$NDKToolchainClangRoot$\$NDKToolchainArmType$-ar.exe'
  	.Linker            	= '$NDKToolchainClangLinker$'
  	.Strip			   	= '$NDKToolchainClangRoot$\$NDKToolchainArmType$-strip.exe'
  	.ObjCopy		   	= '$NDKToolchainClangRoot$\$NDKToolchainArmType$-objcopy.exe'
  	.LinkerSystemPaths  = ' -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-rpath-link=$NDKSysRoot$\usr\libs\$NDKToolchainArmType$\19'
						+ ' -Wl,-z,relro -Wl,-z,now -Wl,--fix-cortex-a8'
						+ '-target $NDKToolchainArmTarget$'
	.IncludePaths       + ' -I$NDKSysRoot$\usr\include\arm-linux-androideabi'
	.LinkerSystemLibs   + ' -lunwind'

I'm testing on API LEVEL = 19 and using llvm Clang toolchain with the right target.

Environment Details

Not all of these will be relevant to every bug, but please provide as much
information as you can.

  • NDK Version: r19c
  • Build system: Premake/FastBuild
  • Host OS: Windows
  • NDK API level: 19 (try to test below 21)
@hanseul1795 hanseul1795 added the bug label Nov 4, 2019
@hanseul1795 hanseul1795 changed the title [question]Building a library with ffreestanding flag. Building a library with ffreestanding flag. Nov 4, 2019
@enh-google
Copy link
Collaborator

you've given -ffreestanding to the compiler, which effectively says "i don't use the standard library", and then tried to use the standard library (specifically <signal.h>).

given that the library you're building here is Android's cpufeatures, i can tell you that that definitely doesn't need -ffreestanding, and -- as you've seen -- can't be built with -ffreestanding.

if you have other code which does need -ffreestanding, you'll have to build that separately.

@hanseul1795
Copy link
Author

hanseul1795 commented Nov 7, 2019

@enh-google
Thank you so much for the answer.

I was wondering, is there a case where -ffreestanding flag is absolutely required?

I have no clue why GCC did not complain about that flag but Clang did.

-ffreestanding flag definition is different in those compilers?

@enh-google
Copy link
Collaborator

the only time you need -ffreestanding is when you (a) can't call the C library or (b) don't even have a standard C library. the most common use is the kernel. the C library's startup code (which needs to avoid calling anything that isn't set up yet) is another case.

an Android app developer should never need -ffreestanding.

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