From owner-freebsd-questions@FreeBSD.ORG Tue Aug 30 10:38:13 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A628416A41F for ; Tue, 30 Aug 2005 10:38:13 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.95]) by mx1.FreeBSD.org (Postfix) with ESMTP id D415543D45 for ; Tue, 30 Aug 2005 10:38:12 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226]) by kane.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j7UAb69t006268; Tue, 30 Aug 2005 13:37:08 +0300 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) by orion.daedalusnetworks.priv (8.13.4/8.13.4) with ESMTP id j7UAb5eB080497; Tue, 30 Aug 2005 13:37:06 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by orion.daedalusnetworks.priv (8.13.4/8.13.4/Submit) id j7UAb2xh080496; Tue, 30 Aug 2005 13:37:02 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) X-Authentication-Warning: orion.daedalusnetworks.priv: keramida set sender to keramida@ceid.upatras.gr using -f Date: Tue, 30 Aug 2005 13:37:02 +0300 From: Giorgos Keramidas To: Jonathon McKitrick Message-ID: <20050830103702.GA80388@orion.daedalusnetworks.priv> References: <20050830032917.GA39730@dogma.freebsd-uk.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050830032917.GA39730@dogma.freebsd-uk.eu.org> Cc: freebsd-questions@freebsd.org Subject: Re: Linking standalone NASM binary with libc 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, 30 Aug 2005 10:38:13 -0000 On 2005-08-30 04:29, Jonathon McKitrick wrote: > > I'm doing some experimentation with assembly code based on the int80h.org > tutorials. But since I am going to use malloc and some other functions, > I need to make my code link with libc rather than stand totally on its own. > > ld -s -o foo foo.o -lc > > leaves 'environ' and '__progname' undefined. What is the correct way to link > standalone asm code with needed libraries? That depends on what the ``standalone'' code contains. If your foo.o object file defines a 'main' function, then you can just use cc(1): % tesla:/tmp/foo$ cat -n foo.asm % 1 global main % 2 main: % 3 mov eax,1 ; exit() syscall % 4 mov ebx,1 ; exit code % 5 int 0x80 ; trap into kernel % tesla:/tmp/foo$ nasm -f elf -o foo.o foo.asm ==> % tesla:/tmp/foo$ cc -o foo foo.o % tesla:/tmp/foo$ ./foo % tesla:/tmp/foo$ echo $? % 1 % tesla:/tmp/foo$