From owner-freebsd-questions@FreeBSD.ORG Tue Sep 28 11:52:51 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E452B106566B for ; Tue, 28 Sep 2010 11:52:51 +0000 (UTC) (envelope-from talon@lpthe.jussieu.fr) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by mx1.freebsd.org (Postfix) with ESMTP id 784AB8FC1B for ; Tue, 28 Sep 2010 11:52:51 +0000 (UTC) Received: from parthe.lpthe.jussieu.fr (parthe.lpthe.jussieu.fr [134.157.10.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id o8SBqnMB003360 for ; Tue, 28 Sep 2010 13:52:50 +0200 (CEST) X-Ids: 166 Received: from niobe.lpthe.jussieu.fr (niobe.lpthe.jussieu.fr [134.157.10.41]) by parthe.lpthe.jussieu.fr (Postfix) with ESMTP id 9EF438A258 for ; Tue, 28 Sep 2010 13:52:48 +0200 (CEST) Received: by niobe.lpthe.jussieu.fr (Postfix, from userid 2005) id 76ED240BC; Tue, 28 Sep 2010 13:54:14 +0000 (UTC) Date: Tue, 28 Sep 2010 13:54:14 +0000 From: Michel Talon To: freebsd-questions@freebsd.org Message-ID: <20100928135414.GA17159@lpthe.jussieu.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-Miltered: at jchkmail.jussieu.fr with ID 4CA1D711.006 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 4CA1D711.006/134.157.10.1/parthe.lpthe.jussieu.fr/parthe.lpthe.jussieu.fr/ Subject: Re: ld(1) cannot find entry symbol _start; X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2010 11:52:52 -0000 Paul B Mahol said: On 9/28/10, Anton Shterenlikht wrote: > > I'm trying to learn the very basics of the > > compile - assemble - link process on FreeBSD. > > Please don't shoot me. > .... > > Then I try to link the object file into > > an executable: > > > > % ld tmp.o > > You are missing something in above command. > More precisely, if you run gcc -v on a C file you get someting like: /usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib -L/usr/lib /var/tmp//cco5EINk.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o where the object file produced by compilation and assembling is /var/tmp//cco5EINk.o That is adds several other object files to your own in order to get an executable. In particular the start symbol, at which execution begins is in /usr/lib/crt1.o as you can see from niobe% nm /usr/lib/crt1.o w _DYNAMIC 00000000 D __progname U _fini U _init U _init_tls 00000000 T _start 00000020 t _start1 00000000 r abitag U atexit 00000004 C environ U exit U main which shows that _start is defined here, (but not e.g. _init). On the other hand the function main() which is defined in your program is referred to but undefined here. -- Michel TALON