delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:reply-to:subject:to:references:from:message-id | |
:date:mime-version:in-reply-to:content-type | |
:content-transfer-encoding; q=dns; s=default; b=EQqv+icot3ZXSA6P | |
uiWJ5Kj9aOSqZwTEEJeJ9QfSrboXlcxQDch6hZwmw6CL5E+FTbM+/RmfzWbRW6r2 | |
zF2c/gYb8L29M+HaOpVS27tJvN2X7Owj6+WvqTz+seSgvSS/kp0DFFSXQcfG/pwv | |
wJTw9/zHFcKtZpI5koK9mcvLGIM= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:reply-to:subject:to:references:from:message-id | |
:date:mime-version:in-reply-to:content-type | |
:content-transfer-encoding; s=default; bh=1HxzAnifQnK3BNcNT4cihw | |
ycVEg=; b=duONxfn04zCzmDpy5ntf/eDAUMc7kofT9jNuXBlFRUvYCfQ8QBB7rC | |
Pcd9fnDtnxqWgCFi5G8DRn9mhXzH3QPlR5APlV/nKyZUBq99d6WfkgUq/czFWO96 | |
ht4wLtR/Ptz7pFxojxvSEz7LjTCgqkk1CJT+BFMMihKcV1fVtjzZU= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Spam-SWARE-Status: | No, score=-3.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=norman, Norman, Arthur, arthur |
X-HELO: | smtp-out-so.shaw.ca |
Reply-To: | Brian DOT Inglis AT SystematicSw DOT ab DOT ca |
Subject: | Re: linker fails with multiple definitions after inline thread_local var within class |
To: | cygwin AT cygwin DOT com |
References: | <alpine DOT WNT DOT 2 DOT 00 DOT 1911141816490 DOT 14912 AT panamint> |
From: | Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca> |
Openpgp: | preference=signencrypt |
Message-ID: | <f5b26568-67dc-1dfe-a35b-248f1644aed9@SystematicSw.ab.ca> |
Date: | Thu, 14 Nov 2019 16:45:03 -0700 |
User-Agent: | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 |
MIME-Version: | 1.0 |
In-Reply-To: | <alpine.WNT.2.00.1911141816490.14912@panamint> |
X-IsSubscribed: | yes |
On 2019-11-14 11:23, Arthur Norman wrote: > When I run this on Ubuntu-x86_64, Macintosh(clang) or a Raspberry pi the code > links and when it runs it just prints 999 - which is the behaviour that I > expect. On both Cygwin and using x86_64-w64-mingw32-g++ (and i686) I get a > linker diagnostic of the form> ./tltest.sh > /usr/lib/gcc/x86_64-pc-cygwin/8.3.0/../../../../x86_64-pc-cygwin/bin/ld: > /tmp/cczVTcZ1.o:t2.cpp:(.text+0x86): multiple definition of > `TLS init function for Data::valref'; > /tmp/ccyLQlRb.o:t1.cpp:(.text+0x4a): first defined here > collect2: error: ld returned 1 exit status > > I believe that given the specification of C++17 "inline" variables this is > incorrect, but there are better experts who may be able to explain > otherwise.> > When people raise issues here I often see other asking "Why are you doing > that?". This is a cut-down version of my real code where rather than storing > a reference to the thread_local Record that I am interested in in a simple > array (tvec) at a fixed offset (1) I store and retrieve a referece to it > using TlsAlloc(), TlsGetValue and TlsSetValue - those being the Microsoft API > for thread-local access, and for my purposes my measurements suggest that > using them gives me useful performance gains over the emutls code that g++ > creates on the relevant platforms.> And I am then (trying to) build a header-only library (for which t.h is the > surrogate here) which can be included from several other compilation units > but by virtue of "inline variables" its private (including thread- local) > date can be defined within that header file so that the files that #include > the header-only library do not need to contain anything beyond uses of it. To > illustrate this I have two source files which each include t.h but the bad > behaviour does not need any other code in the first one! The second just > contains a tiny main program that inspects data from the library data.> > Have I misunderstood C++ and so am I doing something wrong or is this a > g++/Windows bug? You appear to be running into a conflict with Cygwin managing Windows TLS, as Cygwin does its own messing around to support Unix/Linux/POSIX/g++ semantics for TLS and everything else under Windows. You should either use the supplied API, or write a Windows program that allows you to control TLS within Windows rules on what you can do with it. Otherwise you will have to get deep into the changeable and not directly supported underbelly of the Cygwin implementation. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |