ld.exe: cannot find entry symbol _start

0

I am receiving the warning after I have added -nostdlib to the linker flags.

tricore/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to c0000000

The linking is done as follows:

$(OUTDIR)/$(BINARY_NAME).elf: $(OUTDIR) $(OBJ) $(TRICORE_TOOLS)/bin/tricore-gcc -Tld/iRAM.ld -Wl,--no-warn-flags -Wl, --gc-sections -Wl,-n -nostdlib -o $@ $(OBJ) C:\OpenSSL-Win32\lib\MinGW \libssl-1_1.a C:\OpenSSL-Win32\lib\MinGW\libcrypto-1_1.a

I read that -nostdlib results in not using the standard system startup files or libraries when linking. The file ld/iRAM.ld looks as follows, and as far as i understand, it contains the _start symbol and it is passed to the linker:

ENTRY(_start)

/*
 * Global
 */
/*Program Flash Memory (PFLASH0)*/ 
__PMU_PFLASH0_BEGIN = 0x80000000;
__PMU_PFLASH0_SIZE = 2M;
/*Program Flash Memory (PFLASH1)*/ 
........
........
SECTIONS
{
/*Code-Sections*/

/*
 * Startup code for TriCore
 */
.startup_code  :
{
	PROVIDE(__startup_code_start = .);
........
}
.....
}

I have read, that if I pass the -nostdlib flag to the linker, I need to provide the startup code to it too. Does anyone know what I am doing wrong here?

c
makefile
linker
startup
infineon
asked on Stack Overflow Jul 15, 2018 by jonnyx

1 Answer

1

The ENTRY directive in linker script only specifies the name of the entry point symbol (i.e. function). However you still need to actually provide the function with such name in one of your source files.

Most likely solution is to rename your main function to _start function if you have one. Also note that the _start won't have argc and argv parameters since they are usually provided by the standard library. It also should never return since there is nowhere to return to. Instead you'll have to call platform-specific exit function: exit() syscall on Linux or ExitProcess() on Windows. This, however, might not be necessary if you are working in a freestanding environment (i.e. no OS).

answered on Stack Overflow Jul 15, 2018 by r3mus n0x • edited Jul 15, 2018 by r3mus n0x

User contributions licensed under CC BY-SA 3.0