Date: Mon, 13 Mar 2000 14:24:09 -0600 From: Oscar Bonilla <obonilla@fisicc-ufm.edu> To: Marco van de Voort <marcov@stack.nl> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: inner workings of the C compiler Message-ID: <20000313142409.A18395@fisicc-ufm.edu> In-Reply-To: <20000311133221.B99A02E804@hermes.tue.nl> References: <20000311000014.920E62E802@hermes.tue.nl> <20000310184346.B94441@fisicc-ufm.edu> <20000311133221.B99A02E804@hermes.tue.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h>
#include <sys/types.h>
#include <pwd.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000313142409.A18395>
