From owner-freebsd-questions@freebsd.org Wed Oct 16 07:18:55 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8FD4715D9A1 for ; Wed, 16 Oct 2019 07:18:55 +0000 (UTC) (envelope-from markand@malikania.fr) Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (Client CN "Bizanga Labs SMTP Client Certificate", Issuer "Bizanga Labs CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 46tNvL6MW8z4MT5 for ; Wed, 16 Oct 2019 07:18:54 +0000 (UTC) (envelope-from markand@malikania.fr) Received: from postfix.malikania.fr ([5.135.187.121]) by mwinf5d01 with ME id E7Js2100X2dbEiD037Jt0R; Wed, 16 Oct 2019 09:18:53 +0200 X-ME-Helo: postfix.malikania.fr X-ME-Auth: ZGVtZWxpZXIuZGF2aWRAb3JhbmdlLmZy X-ME-Date: Wed, 16 Oct 2019 09:18:53 +0200 X-ME-IP: 5.135.187.121 Received: from [167.3.108.158] (unknown [77.159.242.250]) by postfix.malikania.fr (Postfix) with ESMTPSA id CA97429030 for ; Wed, 16 Oct 2019 09:18:52 +0200 (CEST) Subject: Re: Problems with ld, libc, and "struct stat" To: freebsd-questions@freebsd.org References: <20191015204400.e33c8f62af711e829288ddae@magnetkern.de> From: David Demelier Message-ID: <47c27361-4e74-05d1-3343-e39526730d85@malikania.fr> Date: Wed, 16 Oct 2019 09:18:52 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191015204400.e33c8f62af711e829288ddae@magnetkern.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 46tNvL6MW8z4MT5 X-Spamd-Bar: +++ Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of markand@malikania.fr has no SPF policy when checking 80.12.242.123) smtp.mailfrom=markand@malikania.fr X-Spamd-Result: default: False [3.33 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; TO_DN_NONE(0.00)[]; AUTH_NA(1.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; RCVD_TLS_LAST(0.00)[]; NEURAL_SPAM_MEDIUM(0.92)[0.923,0]; NEURAL_SPAM_LONG(0.89)[0.888,0]; RCVD_IN_DNSWL_NONE(0.00)[123.242.12.80.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; DMARC_NA(0.00)[malikania.fr]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:3215, ipnet:80.12.240.0/20, country:FR]; MID_RHS_MATCH_FROM(0.00)[]; IP_SCORE(0.62)[ip: (0.09), ipnet: 80.12.240.0/20(1.38), asn: 3215(1.64), country: FR(-0.00)]; RWL_MAILSPIKE_POSSIBLE(0.00)[123.242.12.80.rep.mailspike.net : 127.0.0.17] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2019 07:18:55 -0000 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 > #include > 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