Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp959773ybi; Fri, 14 Jun 2019 06:19:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwnGt00sdO7PklEZnm1M+fWTtleRP3yw8nh9rTaRsOx9p3rCVTAnPGMCx/LC/V2qBjjZzX X-Received: by 2002:a17:90a:a00d:: with SMTP id q13mr11043911pjp.80.1560518367232; Fri, 14 Jun 2019 06:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560518367; cv=none; d=google.com; s=arc-20160816; b=mS/7zWTyjwwYmXs1Zf8dCpONRV2uwuDQ5OmTW5EiRJJBp6vjqsGJCTqeSGpp3mHmnq 7gjKdBVLxHpqTNAQ0FAMD9gn+QAsLNgrP0L8rEezGd3Q4uWDuXCy4bUFpZ8f0y2fdyto kvpIHvdBRlXxpGDT9NCrZnzyZvNTs9QmpMsPAzuoaadxtXCVk3p7d/M9KuStkd6Qgwix zGhJnHiIRRSxcVVYxSGUKlUd1t2ivp/N5qZkLKL/YwE2TSaiYIw28XiwsQeF/5kNk2oH yi8YlEL3LkLVLVlAan8DstY83Hgwl/hvqBfjjLoQNYklrbcx3blAyykPtJbiozN5lS1w S8YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=/v2WHP0/4YyzHUmChvFO66kw0sHLDO7c/iZQSMDPn+0=; b=BpcUBzEvx4VMC42KH7h1wIomLSvkKExiaqsiEJybem+32UXzqOiETaKKgs+c5xzIQS /TOmoGmPJuHIghfZqoiVr0PrSIiEhc0+KRb7Sz69TOT6EzX8vyIqc0ALTdodDl+xhNTi //j1nG5sYu9CwXqD1PzuLB/qiz5pEP59wsKCTzxQvFlrjhUii79zOGKwKEHW2kPogTLP 3suqJhKPkidEOlewU8iM4AIXp7TxS3ZzYWrFwy2Fs/myqfDMBy0trSSl5n2k/WMklnpX c8tUZtkk0iHNYCE9BaM7tJ32CJuIgLciNYeL/nO4rsdLsUPXUpw0+mVmsQ7G4uY4SHMr fr8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=SN7BCSJ2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si2281420plb.28.2019.06.14.06.19.12; Fri, 14 Jun 2019 06:19:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=SN7BCSJ2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728201AbfFNNSl (ORCPT + 99 others); Fri, 14 Jun 2019 09:18:41 -0400 Received: from mail.efficios.com ([167.114.142.138]:34932 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727913AbfFNNSl (ORCPT ); Fri, 14 Jun 2019 09:18:41 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 5DE3825101D; Fri, 14 Jun 2019 09:18:39 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id RJkSqrXB2sYD; Fri, 14 Jun 2019 09:18:39 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id EA71D251018; Fri, 14 Jun 2019 09:18:38 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com EA71D251018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1560518319; bh=/v2WHP0/4YyzHUmChvFO66kw0sHLDO7c/iZQSMDPn+0=; h=Date:From:To:Message-ID:MIME-Version; b=SN7BCSJ2tIIDUvDAz7igtpSNX52BaE4Lxpu6EQVXKUJpfKeGSfWn+z1n7D9DbuYQS WsMoY+jt8wMGZGvqw9zYgR08jY83zl3JDouHkERV7/SEnwBqYjEHNnQEMugVBoYZjP gvmpEYtGTDGROMIdr1AiYB57B8eb5TTuUHcUC9nTxyafRz28yK6Xa7qfUvIwrt1MAO ukrlyWUiqD/kcVn94v1QDF1M78Cr+zbHFQzZx17OxnWqzza3omEQp0CAaERzmmC5bz BKwBgl6Ejv4H/bRYgy4sz/OvyOTpH5wDMlcmCfDqsV0sOFjXQ9Gm3jk0raVFqDJDjK UdEIBC4aXlKAg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id xK7b3jYpLBEk; Fri, 14 Jun 2019 09:18:38 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id CF34325100F; Fri, 14 Jun 2019 09:18:38 -0400 (EDT) Date: Fri, 14 Jun 2019 09:18:38 -0400 (EDT) From: Mathieu Desnoyers To: Florian Weimer Cc: carlos , Joseph Myers , Szabolcs Nagy , libc-alpha , Thomas Gleixner , Ben Maurer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , Rich Felker , linux-kernel , linux-api Message-ID: <1779359826.3226.1560518318701.JavaMail.zimbra@efficios.com> In-Reply-To: <87d0jguxdk.fsf@oldenburg2.str.redhat.com> References: <20190503184219.19266-1-mathieu.desnoyers@efficios.com> <802638054.3032.1560506584705.JavaMail.zimbra@efficios.com> <87ftocwkei.fsf@oldenburg2.str.redhat.com> <1635690189.3049.1560507249693.JavaMail.zimbra@efficios.com> <87tvcsv1pk.fsf@oldenburg2.str.redhat.com> <1190407525.3131.1560516910936.JavaMail.zimbra@efficios.com> <1085273942.3137.1560517301721.JavaMail.zimbra@efficios.com> <87d0jguxdk.fsf@oldenburg2.str.redhat.com> Subject: Re: [PATCH 1/5] glibc: Perform rseq(2) registration at C startup and thread creation (v10) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.12_GA_3803 (ZimbraWebClient - FF67 (Linux)/8.8.12_GA_3794) Thread-Topic: glibc: Perform rseq(2) registration at C startup and thread creation (v10) Thread-Index: XZwhQyoKRjgOfzBSfSbrgHMVjax/Lw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jun 14, 2019, at 3:09 PM, Florian Weimer fweimer@redhat.com wrote: > * Mathieu Desnoyers: > >> But my original issue remains: if I define a variable called __rseq_handled >> within either the main executable or the preloaded library, it overshadows >> the libc one: >> >> efficios@compudjdev:~/test/libc-sym$ ./a >> __rseq_handled main: 0 0x56135fd5102c >> __rseq_abi.cpu_id main: 29 0x7fcbeca6d5a0 >> efficios@compudjdev:~/test/libc-sym$ LD_PRELOAD=./s.so ./a >> __rseq_handled s.so: 0 0x558f70aeb02c >> __rseq_abi.cpu_id s.so: -1 0x7fdca78b7760 >> __rseq_handled main: 0 0x558f70aeb02c >> __rseq_abi.cpu_id main: 27 0x7fdca78b7760 >> >> Which is unexpected. > > Why is this unexpected? It has to be this way if the main program uses > a copy relocation of __rseq_handled. As long as there is just one > address across the entire program and ld.so initializes the copy of the > variable that is actually used, everything will be fine. Here is a printout of the __rseq_handled address observed by ld.so, it does not match: LD_PRELOAD=./s.so ./a elf: __rseq_handled addr: 7f501c98a140 __rseq_handled s.so: 0 0x55817a88d02c __rseq_abi.cpu_id s.so: -1 0x7f501c983760 __rseq_handled main: 0 0x55817a88d02c __rseq_abi.cpu_id main: 27 0x7f501c983760 This is with the following in a.c: #include #include __thread struct rseq __rseq_abi __attribute__ ((tls_model ("initial-exec"))) = { .cpu_id = -1, }; int __rseq_handled; int main() { fprintf(stderr, "__rseq_handled main: %d %p\n", __rseq_handled, &__rseq_handled); fprintf(stderr, "__rseq_abi.cpu_id main: %d %p\n", __rseq_abi.cpu_id, &__rseq_abi); return 0; } As we can see, the state of __rseq_handled observed by the preloaded lib and the program is "0", but should really be "1". This can be explained by ld.so not using the same address as the rest of the program, but how can we fix that ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com