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

Assembly code macros not working #53

Open
myan-o opened this issue May 4, 2024 · 11 comments
Open

Assembly code macros not working #53

myan-o opened this issue May 4, 2024 · 11 comments

Comments

@myan-o
Copy link

myan-o commented May 4, 2024

I have defined a macro in lib1funcs.S, but it seems that the macro is not visible in #include "ieee754-sf.S".
It seems like there will be an error if it is commented out.
If the file has a large number of characters, it seems to cause a macro undefined error. Is there a limit to the buffer size?

/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
: Assembler messages:
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:11: Error: unknown opcode or format name 'lea
f_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:21: Error: unknown opcode or format name 'lea
f_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:27: Error: unknown opcode or format name 'lea
f_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:45: Error: unknown opcode or format name 'lea
f_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:55: Error: unknown opcode or format name 'lea
f_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:67: Error: unknown opcode or format name 'lea
f_entry'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:141: Error: unknown opcode or format name 'le
af_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:183: Error: unknown opcode or format name 'le
af_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:196: Error: unknown opcode or format name 'le
af_return'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:207: Error: unknown opcode or format name 'do
_nsau'
/data/data/com.termux/files/usr/tmp/ccfRtRCu.s
:232: Error: unknown opcode or format name 'le
af_return'

build.sh

#!/bin/bash
# after of "ct-ng xtensa-esp32s3-elf"
ROOT_DIR="/data/data/com.termux/files/home/git/crosstool-NG"
BUILD_DIR="$ROOT_DIR/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/"

${BUILD_DIR}/build/build-cc-gcc-core/gcc/xgcc \
  -B${BUILD_DIR}/build/build-cc-gcc-core/gcc/ \
  -B${BUILD_DIR}/buildtools/xtensa-esp32s3-elf/bin/ \
  -B${BUILD_DIR}/buildtools/xtensa-esp32s3-elf/lib/ \
  -isystem ${BUILD_DIR}/buildtools/xtensa-esp32s3-elf/include \
  -isystem ${BUILD_DIR}/buildtools/xtensa-esp32s3-elf/sys-include \
  -I${BUILD_DIR}/src/gcc/libgcc \
  -I${BUILD_DIR}/src/gcc/gcc \
  -I${BUILD_DIR}/src/gcc/include \
  -o _addsubsf3_s.o \
  -DL_addsubsf3 \
  -c ${BUILD_DIR}src/gcc/libgcc/config/xtensa/lib1funcs.S

xgcc -v

Using built-in specs.
COLLECT_GCC=/data/data/com.termux/files/home/g
it/crosstool-NG/.build-xtensa-esp32s3-elf/xten
sa-esp32s3-elf//build/build-cc-gcc-core/gcc/xg
cc
Target: xtensa-esp32s3-elf
Configured with: /data/data/com.termux/files/h
ome/git/crosstool-NG/.build-xtensa-esp32s3-elf
/xtensa-esp32s3-elf/src/gcc/configure --build=
aarch64-linux-android --host=aarch64-linux-and
roid --target=xtensa-esp32s3-elf --prefix=/dat
a/data/com.termux/files/home/git/crosstool-NG/
.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/b
uildtools --exec_prefix=/data/data/com.termux/
files/home/git/crosstool-NG/.build-xtensa-esp3
2s3-elf/xtensa-esp32s3-elf/buildtools --with-l
ocal-prefix=/data/data/com.termux/files/home/g
it/crosstool-NG/builds/xtensa-esp32s3-elf/xten
sa-esp32s3-elf --with-sysroot=/data/data/com.t
ermux/files/home/git/crosstool-NG/builds/xtens
a-esp32s3-elf/xtensa-esp32s3-elf --with-native
-system-header-dir=/include --with-newlib --en
able-threads=no --disable-shared --with-pkgver
sion='crosstool-NG esp-13.2.0_20240305' --disa
ble-__cxa_atexit --disable-libgomp --disable-l
ibmudflap --disable-libmpx --disable-libssp --
disable-libquadmath --disable-libquadmath-supp
ort --disable-libstdcxx-verbose --disable-libs
tdcxx --with-gmp=/data/data/com.termux/files/h
ome/git/crosstool-NG/.build-xtensa-esp32s3-elf
/xtensa-esp32s3-elf/buildtools --with-mpfr=/da
ta/data/com.termux/files/home/git/crosstool-NG
/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/
buildtools --with-mpc=/data/data/com.termux/fi
les/home/git/crosstool-NG/.build-xtensa-esp32s
3-elf/xtensa-esp32s3-elf/buildtools --with-isl
=/data/data/com.termux/files/home/git/crosstoo
l-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-
elf/buildtools --enable-lto --enable-target-op
tspace --without-long-double-128 --disable-nls
 --enable-multiarch --enable-languages=c --ena
ble-threads=posix --with-gnu-ld --disable-__cx
a_atexit --without-headers   --disable-bootstr
ap --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zst
d
gcc version 12.2.0 (crosstool-NG esp-13.2.0_20
240305) 
@igrr
Copy link
Member

igrr commented May 4, 2024

Assembler on its own doesn't support C preprocesor directives like #include. When you compile an assembly source file using GCC, there is an option to automatically run the source file through C preprocesor before passing it to the assembler. By default, GCC decides whether to do this or not based on the file extension. Assembly source files with .S extension are passed through the preprocesor, source files with .s extension are not. You can override this behavior using -x assembler-with-cpp option.

@myan-o
Copy link
Author

myan-o commented May 4, 2024

Where should I set it? If I set it to "CT_EXTRA_CFLAGS_FOR_BUILD" or "CT_EXTRA_CFLAGS_FOR_HOST", I get a syntax error when compiling test.c.

Are there instructions for building xtensa-esp32s3-elf?

@igrr
Copy link
Member

igrr commented May 4, 2024

Could you please describe what you are trying to do? What is the contents of test.c? What command are you running to compile it?

@myan-o
Copy link
Author

myan-o commented May 4, 2024

Could you please describe what you are trying to do? What is the contents of test.c? What command are you running to compile it?

the contents of test.c
int main() { return 0; }

@myan-o
Copy link
Author

myan-o commented May 4, 2024

build options

if [ uname -o == "Android" ]
then
config_value "$CT_CONFIG_FILE" "CT_CFLAGS_FOR_BUILD" "-I${PREFIX}/include -fPIE"
config_value "$CT_CONFIG_FILE" "CT_LDFLAGS_FOR_BUILD" "-L${PREFIX}/lib -fPIE -pie"
config_value "$CT_CONFIG_FILE" "CT_EXTRA_CFLAGS_FOR_BUILD" "-I${PREFIX}/include -fPIE"
config_value "$CT_CONFIG_FILE" "CT_EXTRA_LDFLAGS_FOR_BUILD" "-L${PREFIX}/lib -fPIE -pie"
config_value "$CT_CONFIG_FILE" "CT_EXTRA_CFLAGS_FOR_HOST" "-I${PREFIX}/include -fPIE"
config_value "$CT_CONFIG_FILE" "CT_EXTRA_LDFLAGS_FOR_HOST" "-L${PREFIX}/lib -fPIE -pie"
config_append "$CT_CONFIG_FILE" ".*_EXTRA_CONFIG_ARRAY" "\2 --with-gnu-ld --disable-__cxa_atexit --without-headers"
fi

config_value "$CT_CONFIG_FILE" "CT_HOST" "$CT_HOST"
config_value "$CT_CONFIG_FILE" "CT_BUILD" "$CT_BUILD"
config_value "$CT_CONFIG_FILE" "CT_WORK_DIR" "$CT_WORK_DIR"
config_value "$CT_CONFIG_FILE" "CT_BUILD_TOP_DIR" "${CT_WORK_DIR}/${CT_TARGET}"
config_value "$CT_CONFIG_FILE" "CT_SRC_DIR" "${CT_BUILD_TOP_DIR}/src"
config_enable "$CT_CONFIG_FILE" "CT_DEBUG_CT_SAVE_STEPS"
config_append "$CT_CONFIG_FILE" ".*_EXTRA_CONFIG_ARRAY" "\2 --disable-bootstrap --disable-werror"
config_append "$CT_CONFIG_FILE" "CT_EXTRA_CFLAGS_FOR_BUILD" "\2 -x assembler-with-cpp"
config_append "$CT_CONFIG_FILE" "CT_EXTRA_CFLAGS_FOR_HOST" "\2 -x assembler-with-cpp"

config_enable "$CT_CONFIG_FILE" "CT_EXPERIMENTAL"
config_enable "$CT_CONFIG_FILE" "CT_ALLOW_BUILD_AS_ROOT"
config_enable "$CT_CONFIG_FILE" "CT_ALLOW_BUILD_AS_ROOT_SURE"
}

@myan-o
Copy link
Author

myan-o commented May 4, 2024

Even if the -x assembler-with-cpp option is specified, an error occurs.

cd crosstool-NG/
.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build
/build-cc-gcc-core/xtensa-esp32s3-elf/libgcc

make

# If this is the top-level multilib, build all the other
# multilibs.
make[1]: Entering directory '/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/xtensa-esp32s3-elf/libgcc'
make[2]: Entering directory '/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/xtensa-esp32s3-elf/esp32-psram/libgcc'
# If this is the top-level multilib, build all the other
# multilibs.
/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/./gcc/xgcc -B/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/./gcc/ -B/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/buildtools/xtensa-esp32s3-elf/bin/ -B/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/buildtools/xtensa-esp32s3-elf/lib/ -isystem /data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/buildtools/xtensa-esp32s3-elf/include -isystem /data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/buildtools/xtensa-esp32s3-elf/sys-include    -g -O2 -mlongcalls -idirafter /data/data/com.termux/files/home/git/crosstool-NG/builds/xtensa-esp32s3-elf/xtensa-esp32s3-elf/include -g -Os -x assembler-with-cpp -mfix-esp32-psram-cache-issue -O2  -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -mlongcalls -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -mlongcalls -I. -I. -I../../.././gcc -I/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/src/gcc/libgcc -I/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/src/gcc/libgcc/. -I/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/src/gcc/libgcc/../gcc -I/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/src/gcc/libgcc/../include  -DHAVE_CC_TLS  -x assembler-with-cpp  -o _addsubsf3_s.o -MT _addsubsf3_s.o -MD -MP -MF _addsubsf3_s.dep -DSHARED -DL_addsubsf3 -xassembler-with-cpp -c /data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/src/gcc/libgcc/config/xtensa/lib1funcs.S
/data/data/com.termux/files/usr/tmp/ccoYgST1.s: Assembler messages:
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:18: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:28: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:34: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:52: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:62: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:74: Error: unknown opcode or format name 'leaf_entry'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:148: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:190: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:203: Error: unknown opcode or format name 'leaf_return'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:214: Error: unknown opcode or format name 'do_nsau'
/data/data/com.termux/files/usr/tmp/ccoYgST1.s:239: Error: unknown opcode or format name 'leaf_return'
make[2]: *** [Makefile:491: _addsubsf3_s.o] Error 1
make[2]: Leaving directory '/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/xtensa-esp32s3-elf/esp32-psram/libgcc'
make[1]: *** [Makefile:1211: multi-do] Error 1
make[1]: Leaving directory '/data/data/com.termux/files/home/git/crosstool-NG/.build-xtensa-esp32s3-elf/xtensa-esp32s3-elf/build/build-cc-gcc-core/xtensa-esp32s3-elf/libgcc'
make: *** [Makefile:127: all-multi] Error 2

@myan-o
Copy link
Author

myan-o commented May 6, 2024

After removing -DL_addsubsf3, the compilation went through.

@myan-o
Copy link
Author

myan-o commented May 6, 2024

Macro definition in lib1funcs.S doesn't seem to work

@myan-o myan-o changed the title Syntax error in assembler #include Assembly code macros not working May 6, 2024
@myan-o
Copy link
Author

myan-o commented May 6, 2024

It seems that the macro is not visible in #include "ieee754-sf.S".

@myan-o
Copy link
Author

myan-o commented May 7, 2024

If the file has a large number of characters, it seems to cause a macro undefined error. Is there a limit to the buffer size?

@Lapshin
Copy link
Collaborator

Lapshin commented Jun 17, 2024

Are there instructions for building xtensa-esp32s3-elf?

xtensa-esp32s3-elf is a part of xtensa-esp-elf toolchain. To build refer to .gitlab-ci.yml script https://github.com/espressif/crosstool-NG/blob/esp-1.26.x/.gitlab-ci.yml#L239-L247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants