Define a symbol for an assembly (.s) source file in Android.mk?

半世苍凉 提交于 2020-01-03 01:51:09

问题


Is there a simple way to define a symbol for the Android NDK toolchain's assembler from the Android.mk file?

My objective is to be able to build a native library made up from several .C and .s (assembler) files compiled and tuned for either ARMV6 or ARMV7A EABIS, with all the required conditional compilation driven by simply modifying the APP_ABI value on the Application.mk file.

First I have succesfully used the ifeq() directives available in Android.mk to query the value of the APP_ABI value and then conditionaly execute different parts of the build script.

Then I tried to use this functionality in order to conditionally inject a symbol (via -D), like this:

# Compilation Flags
ifeq ($(TARGET_ARCH_ABI),armeabi)
   LOCAL_CFLAGS += -DTARGET_ARMEABI -marm  -mtune='arm1136jf-s' -ffast-math -O3 -march=armv6 -fvisibility=hidden 
else
   #armeabi-v7a
   LOCAL_CFLAGS += -marm -ffast-math -O3 -march=armv7-a -fvisibility=hidden
endif

The C source code files find the TARGET_ARMEABI symbol properly defined, however the assembler files don't. (I require this in order to define proper EABI attributes according the architecture). This is an example of how I attempt to conditionally define EABI attributes in the assembly language files:

.ifdef TARGET_ARMEABI
    .arch armv6
    .fpu softvfp
    .eabi_attribute 23, 1
    .eabi_attribute 24, 1
    .eabi_attribute 25, 1
    .eabi_attribute 26, 2
    .eabi_attribute 30, 2
    .eabi_attribute 18, 4
.else
    .arch armv7-a
    .eabi_attribute 27, 3
    .fpu vfp
    .eabi_attribute 23, 1
    .eabi_attribute 24, 1
    .eabi_attribute 25, 1
    .eabi_attribute 26, 2
    .eabi_attribute 30, 2
    .eabi_attribute 18, 4
.endif

Any pointers or suggestions are greatly appreciated.


回答1:


Assembly files needs to end with capital S (.S or .sx) to be preprocessed by gcc. See GCC doc, 3.2 Options Controlling the Kind of Output about that.

I believe you can cheat from Bionic sources, for example from libc/arch-arm/bionic/memcpy.S.




回答2:


To make TARGET_ARMEABI define visible in assembly file compile it with '-x assembler-with-cpp' option and use standard C preprocessor #ifdef directive in assembly file.



来源:https://stackoverflow.com/questions/17034898/define-a-symbol-for-an-assembly-s-source-file-in-android-mk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!