From owner-freebsd-hackers Mon Mar 13 12:24:47 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from voyager.fisicc-ufm.edu (ip-198-202.guate.net [209.198.197.202]) by hub.freebsd.org (Postfix) with ESMTP id B124237BD6F for ; Mon, 13 Mar 2000 12:24:35 -0800 (PST) (envelope-from obonilla@voyager.fisicc-ufm.edu) Received: (from obonilla@localhost) by voyager.fisicc-ufm.edu (8.9.3/8.9.3) id OAA18418; Mon, 13 Mar 2000 14:24:10 -0600 (CST) (envelope-from obonilla) Date: Mon, 13 Mar 2000 14:24:09 -0600 From: Oscar Bonilla To: Marco van de Voort Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: inner workings of the C compiler Message-ID: <20000313142409.A18395@fisicc-ufm.edu> References: <20000311000014.920E62E802@hermes.tue.nl> <20000310184346.B94441@fisicc-ufm.edu> <20000311133221.B99A02E804@hermes.tue.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre1i In-Reply-To: <20000311133221.B99A02E804@hermes.tue.nl> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sat, Mar 11, 2000 at 02:30:19PM +0100, Marco van de Voort wrote: > P.s. Could you sent me a minimal C program linking to libc, and the > commandline to compile it with -nostdlib ? > > I could throw all these experiences with non standard linking in a > little tex doc. ( --nostdlib with and without libc, pure assembler > instead of c (no gcc), some small chapter about syscall conventions > etc) Here's what I have for a test program: ----- #include #include #include int main () { struct passwd *password; while ( (password = getpwent()) != NULL ) { printf("login: %s\n", password->pw_name); } password = getpwnam("root"); printf("root has uid: %d\n", password->pw_uid); password = getpwuid(0); printf("uid 0 is %s\n", password->pw_name); return 0; } ----- I copied /usr/src/lib/libc and /usr/src/lib/csu to the parent dir of this test, and thus my makefile is: ----- all: get-test get-test.o: get-test.c cc -g -Wall -pedantic -ansi -c -I../libc/include get-test.c get-test: get-test.o cc -g -nostdlib -static -L../libc -o get-test \ ../csu/i386-elf/crt1.o \ ../csu/i386-elf/crti.o \ ../csu/i386-elf/crtbegin.o \ get-test.o \ ../csu/i386-elf/crtend.o \ ../csu/i386-elf/crtn.o \ -lc clean: rm -f nss-test get-test *.o *.core *.*~ ----- The ordering above was pointed to me by Chuck Robey who got it using the -v flag to cc (which shows you what the C compiler is doing to get good links). I'm not 100% sure that the -lc should be at the end... more likely it should be right after (before?) my object file (get-test.o), but it seems to work both ways. regards, -oscar -- pgp public key: finger obonilla@fisicc-ufm.edu pgp fingerprint: 6D 18 8C 90 4C DF F0 4B DF 35 1F 69 A1 33 C7 BC To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message