From owner-freebsd-hackers Thu Mar 13 15: 5:41 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C885A37B401 for ; Thu, 13 Mar 2003 15:05:39 -0800 (PST) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0D24543FA3 for ; Thu, 13 Mar 2003 15:05:39 -0800 (PST) (envelope-from marcel@xcllnt.net) Received: from ns1.xcllnt.net (localhost [127.0.0.1]) by ns1.xcllnt.net (8.12.8/8.12.8) with ESMTP id h2DN5cSd058414; Thu, 13 Mar 2003 15:05:38 -0800 (PST) (envelope-from marcel@ns1.xcllnt.net) Received: (from marcel@localhost) by ns1.xcllnt.net (8.12.8/8.12.8/Submit) id h2DN5cw1058413; Thu, 13 Mar 2003 15:05:38 -0800 (PST) Date: Thu, 13 Mar 2003 15:05:38 -0800 From: Marcel Moolenaar To: Joe Marcus Clarke Cc: hackers@FreeBSD.ORG Subject: Re: Question on gcc linker and -pthread Message-ID: <20030313230538.GA58315@ns1.xcllnt.net> References: <1047586732.84063.10.camel@gyros> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1047586732.84063.10.camel@gyros> User-Agent: Mutt/1.5.1i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Mar 13, 2003 at 03:18:52PM -0500, Joe Marcus Clarke wrote: > I've noticed something I think is strange with gcc, the -shared flag, > and -pthread on -STABLE. I'm hoping someone can enlighten me as to why > this happens or if it's a bug. If I compile something with the > following command, I do not see libc_r.so linked in the resulting > object: > > cc -shared -pthread -o xxx.so xxx.c > > However, if I replace -pthread with -lc_r, it works. Also, if I change > the command to: > > cc -Wl,-shared -pthread -o xxx.so xxx.c > > I also see libc_r.so linked in. Is this expected behavior? libtool > seems to like the former -shared syntax which is causing some problems > with some GTK themes. Thanks. The -shared option tells the compiler driver that you're trying to create a shared object. In that case -lc_r is not added to the link line. Adding -lc_r explicitly is dangerous, because now the linker will construct a shared object that has code linked in from an archive library that has not been compiled with PIC. Consequently, some architectures (eg ia64) may barf when you try to link against this shared object because it may contain invalid relocations. Using -Wl,-shared tricks the compiler driver in thinking you are creating an executable. It will therefore make sure dependencies are correct by adding -lc_r on the link line. You tell the linker however that you're creating a shared object, but now it also has -lc_r explicitly. Again, this can result in a bad shared object. I don't think there's a bug. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message