Search code examples
linuxassemblynasmld

ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000


This is the error I'm getting while doing a code on assembly language in Linux Ubuntu. Can anyone help me resolve the error?

This is the error that's coming when I use the command ld -o quadratic quadratic.o

The image of Error that's coming.

the code to my asm file is this:

https://github.com/vedantdawange/ASM-Files/blob/main/quadratic.asm


Solution

  • ld by itself links no libraries or startup code. It's suitable for a program where you use _start as an entry point and do I/O via direct calls to the kernel instead of standard C library functions. But your program uses main as its entry point, so it expects to be called by C startup code, and it calls library functions like printf. Hence you should link it like a C program:

    gcc -no-pie -o quadratic quadratic.o
    

    The -no-pie option is needed because your code makes absolute references to static data, e.g. fld qword[b]. gcc by default assumes you want to build a position-independent executable, which can't do that; you'd need to write fld qword[rel b] to produce an rip-relative effective address. So -no-pie asks gcc to link a non-position-independent executable. See Why use RIP-relative addressing in NASM? for more on this.