Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Oct 2019 09:18:52 +0200
From:      David Demelier <markand@malikania.fr>
To:        freebsd-questions@freebsd.org
Subject:   Re: Problems with ld, libc, and "struct stat"
Message-ID:  <47c27361-4e74-05d1-3343-e39526730d85@malikania.fr>
In-Reply-To: <20191015204400.e33c8f62af711e829288ddae@magnetkern.de>
References:  <20191015204400.e33c8f62af711e829288ddae@magnetkern.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Le 15/10/2019 à 20:44, Jan Behrens a écrit :
> Hello,
> 
> I stumbled across a weird problem related stat() that (according to my
> research) seems to be related to an update of the "struct stat"
> C-structure in recent Kernel versions.
> 
> Consider the following two files.
> 
> testlib.c:
> #include <sys/stat.h>
> #include <stdio.h>
> void testfunc() {
>    struct stat sb;
>    stat("testlib.c", &sb);
>    printf("Size of testlib.c is %i bytes.\n", (int)sb.st_size);
> }

Please test the result of stat otherwise sb is left untouched (so all 
member undefined).

> testprog.c:
> extern void testfunc(void);
> int main(int argc, char **argv) {
>    testfunc();
>    return 0;
> }
> 
> Now I run:
> 
> % cc -Wall -c -fPIC -o testlib.o testlib.c
> % cc -Wall -o testprog testlib.o testprog.c
> % ./testprog
> Size of testlib.c is 168 bytes.
> 
> But when I make a shared library like this, I get a different result:
> 
> % ld -shared -o testlib.so testlib.o

Hmm, we usually never call the linker itself when creating shared libraries.

Try instead: cc -shared -o testlib.so testlib.o

HTH

-- 
David



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47c27361-4e74-05d1-3343-e39526730d85>