From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14139 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Fangrui Song Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix tls offsets when p_vaddr%p_align != 0 for TLS_ABOVE_TP Date: Sat, 18 May 2019 00:01:25 +0800 Message-ID: <20190517160125.pg4ugmzq66ciqi6r@gmail.com> References: <20190514020131.GC16415@port70.net> <20190516002051.GX23599@brightrain.aerifal.cx> <20190516074850.GD16415@port70.net> <20190516132246.GY23599@brightrain.aerifal.cx> <20190516225117.GF16415@port70.net> <20190517015043.GA23599@brightrain.aerifal.cx> <20190517123241.GG16415@port70.net> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="169088"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20180223-112-0c5bf3 To: musl@lists.openwall.com Original-X-From: musl-return-14155-gllmg-musl=m.gmane.org@lists.openwall.com Fri May 17 18:01:47 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hRfIo-000hnw-V3 for gllmg-musl@m.gmane.org; Fri, 17 May 2019 18:01:47 +0200 Original-Received: (qmail 13467 invoked by uid 550); 17 May 2019 16:01:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13442 invoked from network); 17 May 2019 16:01:43 -0000 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:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ByoACW5aDrxUXUFSKYsJ53LZmrFjqMG5Cc+aInwV/G0=; b=p9KlNuRs/NM2EMPRAhMBP64XN+kuNv/b3CvAhde4PXL+lGvjW0cb6mFRP5V4WTlKIA NU5LvbsrznPks2OJVLAir7oBvae2uzv4cYDJ5colQSMKvJoLP61lNCL4SoIZaipXxKZY BO12w/5qU8Ey/H5BF7ASq7rm9ahEmjv2W7atL+XU1ZA1QTro3MatX7p1WAcwB4/da6dU uRfcex3Ts85Bwd2QuVJTM6iw3n1B3mxoN+vPiijFRe6U0uCei3LZs1Mf3HAtKvT3pJfe zkwdJg0oNUwzFUOtxczHERi7d+miqZVIicoVM7tNi1nXcGpC2eK287CPt/OXVWd4ACCK A4EA== X-Gm-Message-State: APjAAAUUjBk1vwgeF7AbFdoMGNcTcrZP7S4S2wZwxtczJdxEH66Rk1jS xS4ZtZIR/bLHq97QrUzwelPthlz2A6c= X-Google-Smtp-Source: APXvYqwmg6efpqihpnKfAS8biLcPqhK9inlvkMyhq0TlVYxAHlEvy2Yf9POOgeBY7LjVE2AjS+vyMA== X-Received: by 2002:a17:902:201:: with SMTP id 1mr12942779plc.263.1558108891569; Fri, 17 May 2019 09:01:31 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20190517123241.GG16415@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:14139 Archived-At: On 2019-05-17, Szabolcs Nagy wrote: >* Rich Felker [2019-05-16 21:50:43 -0400]: >> On Fri, May 17, 2019 at 12:51:18AM +0200, Szabolcs Nagy wrote: >> > + p->tls.offset = tls_offset + ( (p->tls_align-1) & >> ~~~~~~~~~ >> >> This should be tls.align. I can fix it up though when applying. > >yes, my bad. I have verified 0001-fix-tls-offsets-when-p_vaddr-p_align-0-for-TLS_ABOVE.patch With the following lld patch, p_vaddr%p_align!=0, the reproduce program in https://bugs.llvm.org/show_bug.cgi?id=41527 works. (a local exec variable defined in executable accessed by another module via `extern __thread int a` (initial exec/generic dynamic)) diff --git i/ELF/InputSection.cpp w/ELF/InputSection.cpp index 1bf67e2a3..ff365ef0c 100644 --- i/ELF/InputSection.cpp +++ w/ELF/InputSection.cpp @@ -594,7 +594,8 @@ static int64_t getTlsTpOffset() { // NB: While the ARM/AArch64 ABI formally has a 2-word TCB size, lld // effectively increases the TCB size to 8 words for Android compatibility. // It accomplishes this by increasing the segment's alignment. - return alignTo(Config->Wordsize * 2, Out::TlsPhdr->p_align); + return alignTo(Config->Wordsize * 2, Out::TlsPhdr->p_align, + Out::TlsPhdr->FirstSec->Addr); case EM_386: case EM_X86_64: // Variant 2. The TLS segment is located just before the thread pointer. (I hope someone can improve my qemu workflow: qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -m 2048 -kernel vmlinuz-vanilla -initrd initramfs-vanilla -append "console=ttyAMA0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main")