From owner-freebsd-current@freebsd.org Tue Jan 2 14:17:20 2018 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 15874EA7ACC for ; Tue, 2 Jan 2018 14:17:20 +0000 (UTC) (envelope-from pdagog@gmail.com) Received: from mail-wr0-x229.google.com (mail-wr0-x229.google.com [IPv6:2a00:1450:400c:c0c::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9BDB680B3E for ; Tue, 2 Jan 2018 14:17:19 +0000 (UTC) (envelope-from pdagog@gmail.com) Received: by mail-wr0-x229.google.com with SMTP id f8so37841726wre.4 for ; Tue, 02 Jan 2018 06:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:jabber-id:user-agent; bh=L4VdoPA5UM58sKgDMHQf4xdymXMJwjGT9oECsYljlg0=; b=Gi6OYBK2wkWHHvYN2ETgV1LB/8jpBEgyd3Lxm5nclmfKQ63j25UZ97Ifpt0DzorSlE xzs58RV1ZXLvz/nPtahC9UXxoIPaGes/gkdg/KBGkAawSUU2MAwLnIVDx3bPKZD1scDA XJgeDk63Zo8J3TLpb65GRtegpG2PW2wLG8/Ohx0WWUG8w/SabXIV7Uhfnp5uHJ8mxBrz phGs6Cx6RxZvLHRFQsthPeoTtLK6x7iGY4Y7KRai6dRonj4TAn0S8gAT2goE0UdlUoPL 7JGiBb55sYXJ+2u21NTl6etZPjFNloqxbXvXrIQu9Rss9pvmoFRAJxaOzu8aqKlNEUw1 kp0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:jabber-id:user-agent; bh=L4VdoPA5UM58sKgDMHQf4xdymXMJwjGT9oECsYljlg0=; b=i6lVE0XF5FEXxulN/Hv9LTGUSGnDO8mO8EXd0+yjMQBVNe1cJBeIDs2SL2fgYPdfwn QTmmudKmQ9EETd8OxzaWGRV0WPsieY/HTi44+hCu20Y+bFphZFbJ170p8yLRrc7azr/S zLLmxs20O2qkbasZ4hrxAhqlVkA/hKMvsV2CBUBjXuzHMW7WW21CLeTA2A1pf188MX+4 ko+9ruHO/dFLp1IduXKdq9WstfZ98MDzeuG8nayOraJkaiUC2dIzIudAwZBsSbuC/oFr yCWO2BRNxGQWNLG6YgqhM88qeyeyqc2gUEPUI83xk2ofSURsTF4QepMrJe2q1n3HkGRF 9l9A== X-Gm-Message-State: AKGB3mIbfZIJA1C2XsYZBrkBeBB1/Vo+bzfZwE4INaO31/SEBbsEOGV3 FZDHxmG/PDPY06JRBcB+Ozw= X-Google-Smtp-Source: ACJfBosZtTpCRfLCSmrpxPJIUnn0mHzUzVmOCBYC6uURkRJ5j+1H5hNu2o+HMwdsKvpfc+M2edM5kA== X-Received: by 10.223.136.243 with SMTP id g48mr35458933wrg.247.1514902637849; Tue, 02 Jan 2018 06:17:17 -0800 (PST) Received: from localhost ([2001:470:1f13:1334:16a:5483:36cd:d8b]) by smtp.gmail.com with ESMTPSA id m68sm56614715wmi.28.2018.01.02.06.17.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 06:17:17 -0800 (PST) Date: Tue, 2 Jan 2018 15:17:14 +0100 From: Pierre DAVID To: Konstantin Belousov Cc: freebsd-current@freebsd.org Subject: Re: Problem with C11 _Atomic Message-ID: <20180102141714.GA16473@vagabond> References: <20180101204740.GA15590@vagabond> <20180101210907.GG1684@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180101210907.GG1684@kib.kiev.ua> Jabber-ID: pdagog@gmail.com User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jan 2018 14:17:20 -0000 On Mon, Jan 01, 2018 at 11:09:07PM +0200, Konstantin Belousov wrote: >On Mon, Jan 01, 2018 at 09:47:40PM +0100, Pierre DAVID wrote: >> Hi, >> >> I'm on a recent current: >> FreeBSD biceps.ma.maison 12.0-CURRENT FreeBSD 12.0-CURRENT #2 r327239: Wed Dec 27 18:25:46 CET 2017 pda@biceps.ma.maison:/usr/obj/usr/src/amd64.amd64/sys/BICEPS amd64 >> >> with clang 5.0.1: >> FreeBSD clang version 5.0.1 (tags/RELEASE_501/final 320880) (based on LLVM 5.0.1) >> Target: x86_64-unknown-freebsd12.0 >> Thread model: posix >> InstalledDir: /usr/bin >> >> I'm having a problem with the following source file: >> >> ------------------------------------------------------------------------------ >> #include >> >> struct foo >> { >> int f1 ; >> char f2 ; >> int f3 ; >> } ; >> >> _Atomic struct foo a ; >> struct foo b ; >> >> int main (int argc, char *argv []) >> { >> b = (struct foo) {.f1 = 5, .f2 = 7, .f3 = 9 } ; >> // atomic_store (&a, b) ; >> a = b ; >> } >> ------------------------------------------------------------------------------ >> >> This code does not compile/link with: >> % cc foo.c -lstdthreads >> /tmp/foo-a0ef26.o: In function `main': >> foo.c:(.text+0x63): undefined reference to `__sync_lock_test_and_set_16' >> cc: error: linker command failed with exit code 1 (use -v to see invocation) >> >> The gcc internal seems to be linked as "cc -v" told me: >> % cc -v foo.c -lstdthreads >> ... >> "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/foo-d7a21b.o -lstdthreads -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o >> >> The problem occurs with "atomic_store(&a, b)" as well as with "a = b". >> >> If I remove the f3 member, the struct foo is only 8 bytes and the code >> compiles/links. >> >> Did I missed something? > >clang issues a calls to libatomic, which we do not provide. >As a workaround, use the following command to compile. The resulting >binary works on all practically usable machines. > $ cc -march=core2 source.c >You might want to turn off sse3/4.1 if you are concerned about older pentium4. > Thanks for your help. I wish that the C11 status of FreeBSD will soon be complete out of the box, without the help of such a hack. Pierre