1

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.

auselen
  • 27,577
  • 7
  • 73
  • 114
  • Do `CFLAGS` get passed to the assembler? Maybe there's a corresponding `ASMFLAGS`? Can you show the complete command lines getting sent to your compiler and assembler respectively? – Carl Norum Jun 11 '13 at 01:09

2 Answers2

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.

auselen
  • 27,577
  • 7
  • 73
  • 114
  • thank you very much, I renamed the extensions to capital S, and replaced the `.ifdef` directives to `#ifdef` as suggested by @bsa2000 and it is working as expected. Cheers! =D –  Jun 11 '13 at 14:54
1

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.

bsa2000
  • 382
  • 2
  • 11