From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 31 02:50:14 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 AEC1116A404 for ; Sat, 31 Mar 2007 02:50:14 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from smtp.utwente.nl (smtp2.utsp.utwente.nl [130.89.2.9]) by mx1.freebsd.org (Postfix) with ESMTP id 3548813C458 for ; Sat, 31 Mar 2007 02:50:14 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from nox.student.utwente.nl (nox.student.utwente.nl [130.89.165.91]) by smtp.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id l2V2QOox000606 for ; Sat, 31 Mar 2007 04:26:24 +0200 From: Pieter de Goeje To: freebsd-hackers@freebsd.org Date: Sat, 31 Mar 2007 04:26:23 +0200 User-Agent: KMail/1.9.6 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200703310426.23953.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact helpdesk@ITBE.utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Subject: 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 02:50:14 -0000 Hello List, I have these files: --- loader.cpp --- #include #include "tls.h" int main() { tls = 0; printf("%d\n", tls); } --- tls.cpp --- #include "tls.h" int __thread tls; --- tls.h --- extern __thread int tls; When I compile them like this: c++ -fPIC -o tls.so tls.cpp -shared c++ -fPIC -o loader loader.cpp tls.so 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 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). 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. FYI, I need tls to work because I'm using OpenMP's tls (#pragma omp threadprivate()) support in gcc 4.3. 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) I would be grateful if someone could shed some light on this. Regards, Pieter de Goeje