sheroy
Posts: 47
Joined: Fri Jun 14, 2013 5:34 pm

Building code with newlib-nano

Sat Dec 08, 2018 12:23 pm

I am using the arm bare metal toolchain (7 2018-q2-update - arm-none-eabi-*) to compile code that uses Newlib in the bare metal environment.

I am unable to figure out the commands in the linker script to do the same.

This is specific to use the NE10 library.

The linker script gives errors such as:

Code: Select all

arm-none-eabi-ld -LC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\ -lNE10  -lc -lg -lm -lnosys   -Map output.map   -o build/kernel7.elf   build/gpio_test_c.o build/serial_c.o build/cstart_c.o build/NE10_sample_real_fft_c.o build/interrupts_c.o build/Ne10Test_c.o build/mailbox_c.o build/start32_s.o -LC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\ -lNE10  -lc -lg -lm -lnosys
arm-none-eabi-ld: error: build/kernel7.elf uses VFP register arguments, c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-fprintf.o) does not
arm-none-eabi-ld: failed to merge target specific data of file c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-fprintf.o)
arm-none-eabi-ld: error: build/kernel7.elf uses VFP register arguments, c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-impure.o) does not

…. truncated...

C:\Users\Sheroy\Desktop\RpiBareMetal\Codes\\libNE10.a(NE10_fft.c.obj): In function `ne10_factor.part.0':
NE10_fft.c:(.text+0x2a0): undefined reference to `__aeabi_idiv'
NE10_fft.c:(.text+0x31e): undefined reference to `__aeabi_idiv'
C:\Users\Sheroy\Desktop\RpiBareMetal\Codes\\libNE10.a(NE10_fft.c.obj): In function `ne10_fft_generate_twiddles_int32':
NE10_fft.c:(.text+0x3a4): undefined reference to `__aeabi_idiv'


… truncated ….


	
c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-mprec.o): In function `__ratio':
mprec.c:(.text.__ratio+0x70): undefined reference to `__aeabi_ddiv'
c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-mprec.o): In function `_mprec_log10':
mprec.c:(.text._mprec_log10+0x28): undefined reference to `__aeabi_dmul'
c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-s_frexp.o): In function `frexp':
s_frexp.c:(.text.frexp+0x48): undefined reference to `__aeabi_dmul'
c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-vfiprintf.o): In function `_vfiprintf_r':
vfprintf.c:(.text._vfiprintf_r+0x115c): undefined reference to `__aeabi_uldivmod'
vfprintf.c:(.text._vfiprintf_r+0x11bc): undefined reference to `__aeabi_uldivmod'
c:\gccarm\7 2018-q2-update\bin\../arm-none-eabi/lib\libc.a(lib_a-fvwrite.o): In function `__sfvwrite_r':
fvwrite.c:(.text.__sfvwrite_r+0x388): undefined reference to `__aeabi_idiv'
C:\Users\Sheroy\Desktop\RpiBareMetal\Codes\\libm.a(lib_a-w_sqrt.o): In function `sqrt':
w_sqrt.c:(.text.sqrt+0xc0): undefined reference to `__errno'
w_sqrt.c:(.text.sqrt+0xd0): undefined reference to `__errno'

… truncated...


It looks like I am unable to successfully link the programs and what extra libraries should I use... I am unsure if only newlib-nano should do the job.

My Makefile script is below:

Code: Select all

ARMGNU ?= arm-none-eabi-
#ARMGNU ?= 

#-IC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\Ne10-master\Ne10-master\inc

INCPATH = 	-Iinclude  \
			-IC:/Users/Sheroy/Desktop/RpiBareMetal/Codes/Ne10-master/Ne10-master/inc 
			 
			
SHLIB =  -LC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\ -lNE10  -lc -lg -lm -lnosys

CPUOPS =   -O2 -mfloat-abi=hard -mthumb -mcpu=cortex-a53 -mfpu=neon-vfpv4  \
			--specs=nano.specs --specs=nosys.specs -lc -lg -lm -lnosys

COPS =   $(CPUOPS) -Wall -nostdlib -nostartfiles -ffreestanding $(INCPATH) 
ASMOPS = $(INCPATH)  $(CPUOPS)

BUILD_DIR = build
SRC_DIR = src


all :kernel7.img


clean:
	del  $(BUILD_DIR)\*.o
	del  $(BUILD_DIR)\*.d
#	del  $(BUILD_DIR)\*.elf


$(BUILD_DIR)/%_c.o: $(SRC_DIR)/%.c
#	mkdir -p $(@D)
	$(ARMGNU)gcc  $(COPS)  -MMD -c $< -o $@


$(BUILD_DIR)/%_s.o: $(SRC_DIR)/%.S
	$(ARMGNU)gcc $(ASMOPS)  -MMD -c $< -o $@


C_FILES = $(wildcard src/*.c)
ASM_FILES = $(wildcard src/*.S)

#OBJ_FILES = $(wildcard $(BUILD_DIR)/*.o)
OBJ_FILES = $(C_FILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%_c.o)
OBJ_FILES += $(ASM_FILES:$(SRC_DIR)/%.S=$(BUILD_DIR)/%_s.o)


DEP_FILES = $(OBJ_FILES:%.o=%.d)
-include $(DEP_FILES)

#include the previously built object files
#OBJ_FILES += $(wildcard $(BUILD_DIR)/*.o)

kernel7.img: $(SRC_DIR)/linker32.ld $(OBJ_FILES) 
	$(ARMGNU)ld $(SHLIB)   -Map output.map   -o $(BUILD_DIR)/kernel7.elf   $(OBJ_FILES) $(SHLIB)
	$(ARMGNU)objcopy $(BUILD_DIR)/kernel7.elf -O binary kernel7.img
	$(ARMGNU)nm -n  $(BUILD_DIR)/kernel7.elf >  $(BUILD_DIR)/output.symbol
	$(ARMGNU)objdump -D $(BUILD_DIR)/kernel7.elf > $(BUILD_DIR)/output.list
	readelf.exe -x .rodata $(BUILD_DIR)/kernel7.elf > $(BUILD_DIR)/rodata.list

LdB
Posts: 1060
Joined: Wed Dec 07, 2016 2:29 pm

Re: Building code with newlib-nano

Sat Dec 08, 2018 3:32 pm

__aeabi_idiv etc is part of the GCC internal library

-lgcc is needed as well as -lm -lc etc

sheroy
Posts: 47
Joined: Fri Jun 14, 2013 5:34 pm

Re: Building code with newlib-nano

Sat Dec 08, 2018 3:51 pm

apparently I am unable to find libgcc from my compiler. Is it a part of the bare metal/embedded environment?

Edit - later I was able to link with libgcc but the errors yet exist. I think it is just a linker issue

sheroy
Posts: 47
Joined: Fri Jun 14, 2013 5:34 pm

[solved] Re: Building code with newlib-nano

Sat Dec 15, 2018 1:45 pm

It looks like after a bit of struggling I was able to fix it. When including libraries not in the default library path the -L option is used to include the new library such as NE10. But including this option apparently does not search the old library paths and this the linking process fails.


I fixed this by my makefile… the makefile is below.

Code: Select all

ARMGNU ?= arm-none-eabi-

# Link for code size
GC=-Wl,--gc-sections

#-IC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\Ne10-master\Ne10-master\inc
INCPATH = 	-Iinclude  \
			-IC:/Users/Sheroy/Desktop/RpiBareMetal/Codes/Ne10-master/Ne10-master/inc 
			 
#-LC:\Users\Sheroy\Desktop\RpiBareMetal\Codes\			

#SHLIB =  -L. -L"C:\GccArm\7 2018-q2-update\arm-none-eabi\lib\hard" -L"C:\GccArm\7 2018-q2-update\lib\gcc\arm-none-eabi\7.3.1\hard" \
		-LC:/Users/Sheroy/Desktop/RpiBareMetal/Codes 


SHLIB =  -L. -L"C:\GccArm\7 2018-q2-update\arm-none-eabi\lib\hard" -L"C:\GccArm\7 2018-q2-update\lib\gcc\arm-none-eabi\7.3.1\hard" \
		-LC:/Users/Sheroy/Desktop/RpiBareMetal/Codes 

#  -lNE10 -lc_nano -lm -lc -lgcc    -lnosys   $(SHLIB)
libs =   -lNE10  -lm  -lc_nano  -lgcc    -lnosys   $(SHLIB)

		
		  
CPUOPS =  -static -O2 -mfloat-abi=hard -mcpu=cortex-a53 -mfpu=neon-vfpv4  

#--specs=nano.specs --specs=nosys.specs -nostdlib
COPS =  $(CPUOPS) -Wall -nostdlib -nostartfiles -ffreestanding   --specs=nano.specs --specs=nosys.specs $(libs) $(INCPATH) $(GC) 
		 
		

ASMOPS = $(INCPATH)  $(CPUOPS) $(libs)

#$(libs) --gc-sections -u _printf_float -u _scanf_float
LDOPS =  $(libs)  --gc-sections -u _printf_float -u _scanf_float



BUILD_DIR = build
SRC_DIR = src


all :kernel7.img


clean:
	del  $(BUILD_DIR)\*.o
	del  $(BUILD_DIR)\*.d
#	del  $(BUILD_DIR)\*.elf


$(BUILD_DIR)/%_c.o: $(SRC_DIR)/%.c
#	mkdir -p $(@D)
	$(ARMGNU)gcc  $(COPS)  -MD -H -c $< -o $@


$(BUILD_DIR)/%_s.o: $(SRC_DIR)/%.S
	$(ARMGNU)gcc $(ASMOPS)  -MD -c $< -o $@


C_FILES = $(wildcard src/*.c)
ASM_FILES = $(wildcard src/*.S)

#OBJ_FILES = $(wildcard $(BUILD_DIR)/*.o)
OBJ_FILES = $(C_FILES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%_c.o)
OBJ_FILES += $(ASM_FILES:$(SRC_DIR)/%.S=$(BUILD_DIR)/%_s.o)


DEP_FILES = $(OBJ_FILES:%.o=%.d)
-include $(DEP_FILES)

#include the previously built object files
#OBJ_FILES += $(wildcard $(BUILD_DIR)/*.o)

kernel7.img: $(SRC_DIR)/linker32.ld $(OBJ_FILES) 
#	$(ARMGNU)ld $(SHLIB)   -Map output.map   -o $(BUILD_DIR)/kernel7.elf   $(OBJ_FILES) $(SHLIB)
	$(ARMGNU)ld   -T src/linker32.ld  -Map output.map -o $(BUILD_DIR)/kernel7.elf   $(OBJ_FILES) $(LDOPS)
	
	$(ARMGNU)objcopy $(BUILD_DIR)/kernel7.elf -O binary kernel7.img
	$(ARMGNU)nm -n  $(BUILD_DIR)/kernel7.elf >  $(BUILD_DIR)/output.symbol
	$(ARMGNU)objdump -D $(BUILD_DIR)/kernel7.elf > $(BUILD_DIR)/output.list
	readelf.exe -x .rodata $(BUILD_DIR)/kernel7.elf > $(BUILD_DIR)/rodata.list


Return to “Bare metal, Assembly language”