cross compile dietlibc with clang for arm

[email protected] Wed, 4 Dec 2019 10:20:40 +0100 (CET)
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
Hi,

I've tried to build dietlibc for an armv7 host (NXP imx7) on an
x86_64 build system with clang.

It almost worked:

...
arm-cortexa7-linux-gnueabihf-clang -I. -isystem include -pipe -nostdinc -D_REENTRANT -Wall -O2 -fstack-protector-all  -march=armv7-a -mtune=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4 --sysroot=/opt/OSELAS.Toolchain/arm-cortexa7-linux-gnueabihf/sysroot-arm-cortexa7-linux-gnueabihf --gcc-toolchain=/opt/OSELAS.Toolchain/arm-cortexa7-linux-gnueabihf -ffunction-sections -fdata-sections -fno-stack-protector -std=gnu99 -fno-builtin-bcmp -fomit-frame-pointer -fstrict-aliasing -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow -c arm/unified.S -Wa,--noexecstack -o bin-arm/unified.o
./dietuglyweaks.h: Assembler messages:
./dietuglyweaks.h:49: Error: unrecognized symbol type ""
./dietuglyweaks.h:50: Error: unrecognized symbol type ""
./dietuglyweaks.h:51: Error: unrecognized symbol type ""
./dietuglyweaks.h:52: Error: unrecognized symbol type ""
./dietuglyweaks.h:53: Error: unrecognized symbol type ""
./dietuglyweaks.h:54: Error: unrecognized symbol type ""
./dietuglyweaks.h:55: Error: unrecognized symbol type ""
./dietuglyweaks.h:56: Error: unrecognized symbol type ""
./dietuglyweaks.h:57: Error: unrecognized symbol type ""
./dietuglyweaks.h:58: Error: unrecognized symbol type ""
./dietuglyweaks.h:60: Error: unrecognized symbol type ""
clang-9: error: assembler command failed with exit code 1 (use -v to see invocation)
make[5]: *** [Makefile:207: bin-arm/unified.o] Error 1

Here is the line of the header dietuglyweaks.h generating the error:

...
.macro DEF_W name
...
.type \name,@function     <== this line
\name:
.endm
...

The problem is that in the arm assembler syntax the char '@' is used to
start a code remark, so in the line reported before the keyword 'function'
becomes a comment and "disappears"; the right char to use on arm would be '%'
as in: .type \name,%function

As a possible solution for this I have the following:

#ifdef __arm__
#define TYPE_FUNC %function
#else
#define TYPE_FUNC @function
#endif

#ifdef __clang__
.macro DEF_G name
.global \name
#ifdef __PIE__
.hidden \name
#endif
.type \name,TYPE_FUNC
\name:
.endm
.macro DEF_W name
.weak \name
#ifdef __PIE__
.hidden \name
#endif
.type \name,TYPE_FUNC
\name:
.endm
#else
...

giorgio