From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 31 14:33:59 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F39A316A403 for ; Sat, 31 Mar 2007 14:33:58 +0000 (UTC) (envelope-from kabaev@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.239]) by mx1.freebsd.org (Postfix) with ESMTP id 730FB13C4AD for ; Sat, 31 Mar 2007 14:33:58 +0000 (UTC) (envelope-from kabaev@gmail.com) Received: by wx-out-0506.google.com with SMTP id s18so729697wxc for ; Sat, 31 Mar 2007 07:33:57 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=CNRJC2BEHWdNed8W8DpqgsyMxZTv/ttussZfB8dT/0v1Ax84KkcJ+HDc2MMgtzYXQJ+Jp0WEIfd0HpJvwev+2HqxcUSvrRincMhJPCwPBzbqVkuvYMCbFIt5ZhQlsLuFvpD5rJwxyF8JG0tfOYwHPrBoKYn2edHyLozKOCkImBA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=pqxHiwVR9p2ZPQqz2j5wqeV+ugUbZ0d9h3kp4BsBYgE2phh1Svcnj9GJc1JqYe3ZhuxVZgoqyZJLa6s+G90Lna+rJmjKXc2HNnqaO7kh9tWt7ORiP5IQvKeOFRcNb70SuMQ8/vUyvj4l96buyvmPgPmp5hJI8psD6vXR8aYvObE= Received: by 10.70.56.4 with SMTP id e4mr5523727wxa.1175349922569; Sat, 31 Mar 2007 07:05:22 -0700 (PDT) Received: from kan.dnsalias.net ( [24.34.98.164]) by mx.google.com with ESMTP id 14sm4719959wrl.2007.03.31.07.05.21; Sat, 31 Mar 2007 07:05:21 -0700 (PDT) Date: Sat, 31 Mar 2007 10:05:15 -0400 From: Alexander Kabaev To: Pieter de Goeje Message-ID: <20070331100515.15b62e92@kan.dnsalias.net> In-Reply-To: <200703310426.23953.pieter@degoeje.nl> References: <200703310426.23953.pieter@degoeje.nl> X-Mailer: Claws Mail 2.8.1 (GTK+ 2.10.11; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: multipart/signed; boundary=Sig_i2A_C2kAIm0sZ0KNAm5Xrlm; protocol="application/pgp-signature"; micalg=PGP-SHA1 Cc: freebsd-hackers@freebsd.org Subject: Re: Thread local storage not working with -fPIC and shared objects X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Mar 2007 14:33:59 -0000 --Sig_i2A_C2kAIm0sZ0KNAm5Xrlm Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sat, 31 Mar 2007 04:26:23 +0200 Pieter de Goeje wrote: > Hello List, >=20 > I have these files: > --- loader.cpp --- > #include > #include "tls.h" >=20 > int main() { > tls =3D 0; > printf("%d\n", tls); > } >=20 > --- tls.cpp --- > #include "tls.h" > int __thread tls; >=20 > --- tls.h --- > extern __thread int tls; >=20 > When I compile them like this: > c++ -fPIC -o tls.so tls.cpp -shared > c++ -fPIC -o loader loader.cpp tls.so >=20 > And run the resulting program, I get: > pyotr@nox:~/projects/misc/tls> ./loader > /libexec/ld-elf.so.1: ./loader: Unsupported relocation type 37 in > non-PLT relocations >=20 > When I omit -fPIC, it runs fine. But I need fPIC for the shared > object on amd64 arch. I've tried it on Linux/i386 (gcc 4.1) and it > ran fine (with fPIC). >=20 > Much to my surprise however, a particularly large application I'm > working on did compile & run on FreeBSD/amd64 using -fpic (lowercase) > and gcc 4.3. Trying -fpic on FreeBSD/i386 resulted in failure. >=20 > FYI, I need tls to work because I'm using OpenMP's tls (#pragma omp=20 > threadprivate()) support in gcc 4.3. >=20 > The workaround I found on FreeBSD/amd64 was linking the main > executable with -fno-PIC, or building everything with -fpic. (both > workarounds didn't work on FreeBSD/i386) >=20 > I would be grateful if someone could shed some light on this. >=20 There is no reason whatsoever to compile main binary code with -f[pP]ic. Executables are not shared libraries and stuffing position independent code into them makes no sense. --=20 Alexander Kabaev --Sig_i2A_C2kAIm0sZ0KNAm5Xrlm Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGDmqbQ6z1jMm+XZYRAlR9AKCCthvWBQFibWpZnGwAYO2Srt3gKACfTpBe RjvoMEvItrccTK97B6x6QHM= =WmDR -----END PGP SIGNATURE----- --Sig_i2A_C2kAIm0sZ0KNAm5Xrlm--