Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Compilation of examples fails because of inapplicable autoconf checks. #586

Open
Ma124 opened this issue Feb 25, 2021 · 0 comments
Open

Comments

@Ma124
Copy link

Ma124 commented Feb 25, 2021

The compilation of the examples fails even after manually dealing with #574 because autoconf tries to run some sanity checks on the compiler.

It tries to compile the following code:

/* confdefs.h */
#define PACKAGE_NAME "freedom-metal"
#define PACKAGE_TARNAME "freedom-metal"
#define PACKAGE_VERSION "v0.1.2"
#define PACKAGE_STRING "freedom-metal v0.1.2"
#define PACKAGE_BUGREPORT "https://github.com/sifive/freedom-metal/issues"
#define PACKAGE_URL "https://github.com/sifive/freedom-metal"
#define PACKAGE "freedom-metal"
#define VERSION "v0.1.2"
/* end confdefs.h.  */

int
main ()
{

  ;
  return 0;
}

Without -nostdlib it fails because the linker cannot find some objects:

$ riscv64-unknown-elf-gcc test.c
/usr/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find crt0.o: No such file or directory
/usr/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lc
/usr/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lgloss
collect2: error: ld returned 1 exit status
Failure with -nostdlib

This fails because riscv64-unknown-elf-gcc cannot find the _start symbol required by bare metal targets.

GCC command to test this
$ cat << 'EOF' > test.c
/* confdefs.h */
#define PACKAGE_NAME "freedom-metal"
#define PACKAGE_TARNAME "freedom-metal"
#define PACKAGE_VERSION "v0.1.2"
#define PACKAGE_STRING "freedom-metal v0.1.2"
#define PACKAGE_BUGREPORT "https://github.com/sifive/freedom-metal/issues"
#define PACKAGE_URL "https://github.com/sifive/freedom-metal"
#define PACKAGE "freedom-metal"
#define VERSION "v0.1.2"
/* end confdefs.h.  */

int
main ()
{

  ;
  return 0;
}
EOF

$ riscv64-unknown-elf-gcc -nostdlib -march=rv32imac -mabi=ilp32 test.c
/usr/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000010054

I have tried circumventing this by including _start in all test source files using the following sed command:

sed -i 's/int$/int main();\nvoid _start() {main();}\nint/g' freedom-metal/configure

That didn't work either.

After that I stopped configure from aborting on errors and just let it continue by changing as_fn_error in line 410 of freedom-metal/configure.
This approach failed because autoconf extracts information from the build process such as the file extension of executable and object files.

Make command to test this
$ make software                                                   
cd /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug/ && \
	CFLAGS="-march=rv32imac -mabi=ilp32 -mcmodel=medlow -ffunction-sections -fdata-sections -I/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/install/include --specs=nano.specs -DMTIME_RATE_HZ_DEF=32768 -O0 -g" \
	/home/ma/src/sifive/freedom-e-sdk/freedom-metal/configure \
	--host=riscv64-unknown-elf \
	--prefix=/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/install \
	--libdir=/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/install/lib/debug \
	--with-builtin-libgloss \
	--with-machine-header=/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal.h \
	--with-machine-inline=/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal-inline.h \
	--with-platform-header=/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal-platform.h
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for riscv64-unknown-elf-strip... riscv64-unknown-elf-strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... riscv64-unknown-elf
checking for riscv64-unknown-elf-gcc... riscv64-unknown-elf-gcc
checking whether the C compiler works... no
configure: error: in `/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug':
configure: error: C compiler cannot create executables
See `config.log' for more details
checking for C compiler default output file name... 
checking for suffix of executables... configure: error: in `/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug':
configure: error: cannot compute suffix of executables: cannot compile and link
See `config.log' for more details

checking whether we are cross compiling... yes
checking for suffix of object files... configure: error: in `/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details

checking whether we are using the GNU C compiler... no
checking whether riscv64-unknown-elf-gcc accepts -g... no
checking for riscv64-unknown-elf-gcc option to accept ISO C89... unsupported
checking whether riscv64-unknown-elf-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of riscv64-unknown-elf-gcc... gcc3
checking for riscv64-unknown-elf-ranlib... riscv64-unknown-elf-ranlib
checking for riscv64-unknown-elf-ar... riscv64-unknown-elf-ar
checking the archiver (riscv64-unknown-elf-ar) interface... ar
checking dependency style of riscv64-unknown-elf-gcc... gcc3
configure: error: in `/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug':
configure: error: The C compiler doesn't define __riscv, which means it's probably not a RISC-V compiler.  You should specify something like --host=riscv64-sifive-elf when building this, as it will only work on RISC-V systems.
See `config.log' for more details
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
touch -c /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug/Makefile
make -C /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug install
make[1]: Entering directory '/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug'
cp /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal.h metal/machine.h
cp /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal-inline.h metal/machine/inline.h
cp /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/metal-platform.h metal/machine/platform.h
make  install-am
make[2]: Entering directory '/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug'
rm -f libmetal.a
riscv64-unknown-elf-ar cru libmetal.a src/drivers/fixed-clock. src/drivers/fixed-factor-clock. src/drivers/inline. src/drivers/riscv_clint0. src/drivers/riscv_cpu. src/drivers/riscv_plic0. src/drivers/sifive_buserror0. src/drivers/sifive_ccache0. src/drivers/sifive_clic0. src/drivers/sifive_fe310-g000_hfrosc. src/drivers/sifive_fe310-g000_hfxosc. src/drivers/sifive_fe310-g000_lfrosc. src/drivers/sifive_fe310-g000_pll. src/drivers/sifive_fe310-g000_prci. src/drivers/sifive_global-external-interrupts0. src/drivers/sifive_gpio-buttons. src/drivers/sifive_gpio-leds. src/drivers/sifive_gpio-switches. src/drivers/sifive_gpio0. src/drivers/sifive_i2c0. src/drivers/sifive_l2pf0. src/drivers/sifive_local-external-interrupts0. src/drivers/sifive_pwm0. src/drivers/sifive_rtc0. src/drivers/sifive_spi0. src/drivers/sifive_test0. src/drivers/sifive_trace. src/drivers/sifive_uart0. src/drivers/sifive_simuart0. src/drivers/sifive_wdog0. src/drivers/ucb_htif0. src/atomic. src/button. src/cache. src/clock. src/cpu. src/entry. src/scrub. src/trap. src/gpio. src/hpm. src/i2c. src/init. src/interrupt. src/led. src/lock. src/memory. src/pmp. src/privilege. src/pwm. src/rtc. src/shutdown. src/spi. src/switch. src/synchronize_harts. src/timer. src/time. src/trap. src/tty. src/uart. src/vector. src/watchdog. 
riscv64-unknown-elf-ar: `u' modifier ignored since `D' is the default (see `U')
riscv64-unknown-elf-ar: src/drivers/fixed-clock.: No such file or directory
make[2]: *** [Makefile:890: libmetal.a] Error 1
make[2]: Leaving directory '/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug'
make[1]: *** [Makefile:1287: install] Error 2
make[1]: Leaving directory '/home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/build/debug'
make: *** [scripts/libmetal.mk:124: /home/ma/src/sifive/freedom-e-sdk/bsp/freedom-e310-arty/install/lib/debug/stamp] Error 2

I no longer have any ideas how to proceed, but this needs investigation by someone with a better knowledge of autoconf.

This is probably the same issue as riscv-pk#7.

I am using Arch Linux and obtained riscv64-unknown-elf-gcc from the AUR, compilation options of gcc can be found here.

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

No branches or pull requests

1 participant