[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gas couldn't handle comments leaved by C preprocessor properly
From: |
address@hidden |
Subject: |
gas couldn't handle comments leaved by C preprocessor properly |
Date: |
Sun, 03 Oct 2021 21:00:24 +0800 |
Hi!
I'm trying to port GCC and binutils to AArch64-Android platform, and
something unusual happened in the process.
I found that GNU as (gas) couldn't handle comments leaved by C preprocessor
properly:
t.c:
#include <stdio.h>
#include <math.h>
int main(int ac, char **av)
{
printf("======== START ========\n");
for (int i = 2; i <= 9; ++i)
{
printf("ln(%d) = ", i);
printf("%.13lf\n", log(i));
}
printf("Hello GCC on Android!!!\n");
return 0;
}
0| $ gcc -v t.c -lm -o t &&./t
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/lto-wrapper
Target: aarch64-linux-android
Configured with: ./configure --with-pic --disable-rpath --with-boot-ldflags=-s
--enable-static --disable-shared --with-system-zlib --with-stage1-ldflags=-s
--with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-libssp
--disable-libgomp --disable-multilib --disable-libitm --disable-docs
--disable-libsanitizer --enable-default-pie --enable-plugins
--with-sysroot=/sdcard/AnSysroot --sysconfdir=/sdcard/TermFiles/etc
--datarootdir=/sdcard/TermFiles/share --build=aarch64-linux-android
--prefix=/data/user/0/bin.mt.plus/home/AnGCC
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64'
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/cc1
-quiet -v -iprefix
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/
t.c -mbionic -fPIC -quiet -dumpbase t.c -dumpbase-ext .c -mlittle-endian
-mabi=lp64 -version -o /data/user/0/bin.mt.plus/files/term/usr/tmp/ccnJNNv5.s
GNU C17 (GCC) version 11.2.0 (aarch64-linux-android)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/include"
ignoring nonexistent directory "/sdcard/AnSysroot/usr/local/include"
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/include-fixed"
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/include"
#include "..." search starts here:
#include <...> search starts here:
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/include
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/include-fixed
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/include
/sdcard/AnSysroot/usr/include
End of search list.
GNU C17 (GCC) version 11.2.0 (aarch64-linux-android)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e798b52f58a07ec743fc344b9abcf23e
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64'
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/as
-v -EL -mabi=lp64 -o /data/user/0/bin.mt.plus/files/term/usr/tmp/ccJC50Pu.o
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccnJNNv5.s
GNU assembler version 2.37 (aarch64-linux-android) using BFD version (GNU
Binutils) 2.37
COMPILER_PATH=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/:/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/
LIBRARY_PATH=/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../:/sdcard/AnSysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 't.'
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/collect2
-plugin
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/liblto_plugin.so
-plugin-opt=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/lto-wrapper
-plugin-opt=-fresolution=/data/user/0/bin.mt.plus/files/term/usr/tmp/cccJxM1d.res
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-ldl -plugin-opt=-pass-through=-lgcc
--sysroot=/sdcard/AnSysroot --eh-frame-hdr -dynamic-linker /system/bin/linker64
-X -EL -maarch64linux -pie -o t
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/crtbegin_dynamic.o
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../..
-L/sdcard/AnSysroot/usr/lib
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccJC50Pu.o -lm -lgcc -lc -ldl -lgcc
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/crtend_android.o
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 't.'
======== START ========
ln(2) = 0.6931471805599
ln(3) = 1.0986122886681
ln(4) = 1.3862943611199
ln(5) = 1.6094379124341
ln(6) = 1.7917594692281
ln(7) = 1.9459101490553
ln(8) = 2.0794415416798
ln(9) = 2.1972245773362
Hello GCC on Android!!!
0| $ gcc t.c -S
0| $ gcc -v -x assembler-with-cpp t.s -lm -o t
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/lto-wrapper
Target: aarch64-linux-android
Configured with: ./configure --with-pic --disable-rpath --with-boot-ldflags=-s
--enable-static --disable-shared --with-system-zlib --with-stage1-ldflags=-s
--with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-libssp
--disable-libgomp --disable-multilib --disable-libitm --disable-docs
--disable-libsanitizer --enable-default-pie --enable-plugins
--with-sysroot=/sdcard/AnSysroot --sysconfdir=/sdcard/TermFiles/etc
--datarootdir=/sdcard/TermFiles/share --build=aarch64-linux-android
--prefix=/data/user/0/bin.mt.plus/home/AnGCC
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64'
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/cc1
-E -lang-asm -quiet -v -iprefix
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/
t.s -mbionic -fPIC -mlittle-endian -mabi=lp64 -fno-directives-only -o
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccx6mwPl.s
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/include"
ignoring nonexistent directory "/sdcard/AnSysroot/usr/local/include"
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/include-fixed"
ignoring duplicate directory
"/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/../../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/include"
#include "..." search starts here:
#include <...> search starts here:
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/include
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/include-fixed
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/include
/sdcard/AnSysroot/usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64'
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/as
-v -EL -mabi=lp64 -o /data/user/0/bin.mt.plus/files/term/usr/tmp/ccBma6ZI.o
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccx6mwPl.s
GNU assembler version 2.37 (aarch64-linux-android) using BFD version (GNU
Binutils) 2.37
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccx6mwPl.s: Assembler messages:
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccx6mwPl.s: Warning: end of file in
comment; newline inserted
COMPILER_PATH=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/:/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/
LIBRARY_PATH=/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/:/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../:/sdcard/AnSysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 't' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 't.'
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/collect2
-plugin
/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/liblto_plugin.so
-plugin-opt=/data/data/bin.mt.plus/home/AnGCC/bin/../libexec/gcc/aarch64-linux-android/11.2.0/lto-wrapper
-plugin-opt=-fresolution=/data/user/0/bin.mt.plus/files/term/usr/tmp/cckEf4L9.res
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-ldl -plugin-opt=-pass-through=-lgcc
--sysroot=/sdcard/AnSysroot --eh-frame-hdr -dynamic-linker /system/bin/linker64
-X -EL -maarch64linux -pie -o t
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/crtbegin_dynamic.o
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib
-L/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../..
-L/sdcard/AnSysroot/usr/lib
/data/user/0/bin.mt.plus/files/term/usr/tmp/ccBma6ZI.o -lm -lgcc -lc -ldl -lgcc
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/crtend_android.o
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/ld:
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/lib/crtbegin_dynamic.o:
in function `_start_main':
crtbegin.c:(.text+0x20): undefined reference to `main'
/data/data/bin.mt.plus/home/AnGCC/bin/../lib/gcc/aarch64-linux-android/11.2.0/../../../../aarch64-linux-android/bin/ld:
crtbegin.c:(.text+0x4c): undefined reference to `main'
collect2: error: ld returned 1 exit status
1| $
In a nutshell, I found that `cpp t.s > t_.s; as t_.s -o t.o` will generate
t.o with no symbol:
0| $ cpp t.s > t_.s; as t_.s -o t.o
t_.s: Assembler messages:
t_.s: Warning: end of file in comment; newline inserted
0| $ nm t.o
0| $
then I begin to research, and perhaps I found where the problem comes from:
(/sdcard/input-file.c is binutils-2.37/gas/input-file.c)
--- /sdcard/input-file.c
+++ input-file.c
@@ -191,7 +191,7 @@
else if (c == '\n')
ungetc ('\n', f_in);
else
- ungetc ('#', f_in);
+ ungetc(c, f_in), ungetc ('#', f_in);
}
else
ungetc (c, f_in);
This part seems like where simple preprocess the input text. When there is
'#' at the beginning of the code with next character isn't 'N' 'A' or '\n', I
think this character and '#' should be sent to ungetc() (so that ftell(f_in)
return 0), but there is only ungetc('#', f_in). I modified input-file.c, and I
successfully solved the problem.
Is it a bug? If not, what should I do instead?
p.s. It's my first time trying to report something to GNU! ;)
- gas couldn't handle comments leaved by C preprocessor properly,
address@hidden <=