Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2162684ybv; Fri, 14 Feb 2020 12:44:25 -0800 (PST) X-Google-Smtp-Source: APXvYqwIQSWcXYM/g9m/a5eXcCCQyFhnevMc9CuuvHGDf+jORPcQuRWTwH4OuXEdfUeCCbpxC8oR X-Received: by 2002:a9d:7489:: with SMTP id t9mr1806055otk.255.1581713065246; Fri, 14 Feb 2020 12:44:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581713065; cv=none; d=google.com; s=arc-20160816; b=lIZmalB7T74gPSHxzOddwg/vb1PIboK6R/HO9Hz4alKh+HmzZo+3koND/XNpzghGix f9nu8wi9bJlzQjw35FN1DfgqJbjuj08QLLJHDUdoZrmJCy2gzClYc6XY1jrM2KdgGq7+ A1TMEdbyRVR58WtRxXei205H5eJX7TPZ/sbsmrMZcp1n29Gb7MY1h3PSD5cKLXJT4Vt8 TMWJynMEBRlUsYIosYNtaZkUWvwktpkvsud9h3c6cFDJmkLHXte9WhpRpvfPRpsqjPE3 EtlI+XVvTzS4mA/hN5U0fqhYvKbhGzo3EW6PzoyyA03cHc1e8cqiS14pSJklrn1SZsg+ yXhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=nO59hUcE7IAJE3zl0mbNkPEwvhdB+UVqeIgDKUs84Ak=; b=A/B/eojVWqgbkJh2PEOSi4tMysLowQsbkv7Mlr8cDQ4vAiZrv1pTbtWJWOmpZfWueJ a1BifjY3q5UFG59JRQASBCUzNSWpQAZ/vc/SFJH7sg1sO+ixEFfb/92Xd1TWq+GuIylL +KX49g1HuNRugiqBa8d0fAAzluzoEv//UAZejnuMgzhk4jO8+tdw8of8j5CbxFI23Dl+ qN1hoT5hTDA9HIHk3sB1SSi3OZNncmnSASNyJ8MSJb635aVE9cVX3Fz/NPjenocTv2Ns eKIQ3zSVoBVm6CkaBnnieENEgSzvMnrjaGNpPwCiYnhION8uUHWq+rqk+C/RruUncacb Bt0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=swshXf0S; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k125si2934046oib.212.2020.02.14.12.44.12; Fri, 14 Feb 2020 12:44:25 -0800 (PST) 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=fail header.i=@gmail.com header.s=20161025 header.b=swshXf0S; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730283AbgBNUmx (ORCPT + 99 others); Fri, 14 Feb 2020 15:42:53 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:39583 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729672AbgBNUmx (ORCPT ); Fri, 14 Feb 2020 15:42:53 -0500 Received: by mail-qk1-f196.google.com with SMTP id a141so642613qkg.6 for ; Fri, 14 Feb 2020 12:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nO59hUcE7IAJE3zl0mbNkPEwvhdB+UVqeIgDKUs84Ak=; b=swshXf0SIC4WNhSIsQrpE90ysrITW7yjyqmRIF0RHAdEvpNJzRA5vPXAaQi7C5gef+ a+r2RfJVkAx03vCINteSPG3v/r9uj0gZaBL2DXtI0xYo17wUHAIw1WklX/M7mAcdVHFV S1PdreyqydjIu+f07MEzMcBhNQ7HfYVJ9HkhdQMBzGaflbNHUWG+RhKP9UL8rJNuRgix rULGzvVhlcEtuwW+rhDJv3N5TiBnHQajiN87L1YghChGndqDX00zxbuy6TtH83DmrNX2 xMyuAEqK86fVXZHObLwPyXLWNJAoRnCLGaUope383wHjgxgXsBbGZvmRxrVnSO6aIQ/r uHjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=nO59hUcE7IAJE3zl0mbNkPEwvhdB+UVqeIgDKUs84Ak=; b=rsRnTAhWPRMPIlZXCQ+SlOWtRUNhCJeszz4iY8obOtWkcvQdGOrDSdQN/dn+IaMJIu uyijT5YQZJHb3/0rS0Jejq4dX3vykRXMH6zd4+zELeO6RrbAU1U97zFI6Cm2TjmCHWWT UOURC0iQQK23yLmzyKn66yttUOgdxwQ3MtbxfW/laohEb/qAuYEDBaANtnVJdqFkgIiR OOFMq9SJ+nQzJ35XR5Ttmvc7AHDoPaSr2niwBsiO7MXR+e7Hxi6SMi75icWlxC2hyYgI k7tIw9nPX20gQ5jrT0qI+l81R+dyIhfyj1udfyjGBkhidKe+mm5P06MRhONNWbTOTCev 7CVQ== X-Gm-Message-State: APjAAAUgFOk+3Y41LAZ5w3DlTGk4P1Qx6eAQESUBle1dt1GOJBAa/1fR UFn3dg9W+b7KUS2GqkqbGvg= X-Received: by 2002:a37:a84f:: with SMTP id r76mr4303279qke.115.1581712971940; Fri, 14 Feb 2020 12:42:51 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id n191sm4033808qkn.6.2020.02.14.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 12:42:51 -0800 (PST) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 14 Feb 2020 15:42:49 -0500 To: Fangrui Song Cc: Arvind Sankar , Nick Desaulniers , jpoimboe@redhat.com, peterz@infradead.org, clang-built-linux@googlegroups.com, Nathan Chancellor , linux-kernel@vger.kernel.org Subject: Re: [PATCH] objtool: ignore .L prefixed local symbols Message-ID: <20200214204249.GA3624438@rani.riverdale.lan> References: <20200213184708.205083-1-ndesaulniers@google.com> <20200213192055.23kn5pp3s6gwxamq@google.com> <20200214061654.GA3136404@rani.riverdale.lan> <20200214180527.z44b4bmzn336mff2@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200214180527.z44b4bmzn336mff2@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 14, 2020 at 10:05:27AM -0800, Fangrui Song wrote: > I know little about objtool, but if it may be used by other > architectures, hope the following explanations don't appear to be too > off-topic:) > > On 2020-02-14, Arvind Sankar wrote: > >Can you describe what case the clang change is supposed to optimize? > >AFAICT, it kicks in when the symbol is known by the compiler to be local > >to the DSO and defined in the same translation unit. > > > >But then there are two cases: > >(a) we have call foo, where foo is defined in the same section as the > >call instruction. In this case the assembler should be able to fully > >resolve foo and not generate any relocation, regardless of whether foo > >is global or local. > > If foo is STB_GLOBAL or STB_WEAK, the assembler cannot fully resolve a > reference to foo in the same section, unless the assembler can assume > (the codegen tells it) the call to foo cannot be interposed by another > foo definition at runtime. I was testing with hidden/protected visibility, I see you want this for the no-semantic-interposition case. Actually a bit more testing shows some peculiarities even with hidden visibility. With the below, the call and lea create relocations in the object file, but the jmp doesn't. ld does avoid creating a plt for this though. .text .globl foo, bar .hidden foo bar: call foo leaq foo(%rip), %rax jmp foo foo: ret > > >(b) we have call foo, where foo is defined in a different section from > >the call instruction. In this case the assembler must generate a > >relocation regardless of whether foo is global or local, and the linker > >should eliminate it. > >In what case does does replacing call foo with call .Lfoo$local help? > > For -fPIC -fno-semantic-interposition, the assembly emitter can perform > the following optimization: > > void foo() {} > void bar() { foo(); } > > .globl foo, bar > foo: > .Lfoo$local: > ret > bar: > call foo --> call .Lfoo$local > ret > > call foo generates an R_X86_64_PLT32. In a -shared link, it creates an > unneeded PLT entry for foo. > > call .Lfoo$local generates an R_X86_64_PLT32. In a -shared link, .Lfoo$local is > non-preemptible => no PLT entry is created. > > For -fno-PIC and -fPIE, the final link is expected to be -no-pie or > -pie. This optimization does not save anything, because PLT entries will > not be generated. With clang's integrated assembler, it may increase the > number of STT_SECTION symbols (because .Lfoo$local will be turned to a > STT_SECTION relative relocation), but the size increase is very small. > > > I want to teach clang -fPIC to use -fno-semantic-interposition by > default. (It is currently an LLVM optimization, not realized in clang.) > clang traditionally makes various -fno-semantic-interposition > assumptions and can perform interprocedural optimizations even if the > strict ELF rule disallows them. FWIW, gcc with no-semantic-interposition also uses local aliases, but rather than using .L labels, it creates a local alias by .set foo.localalias, foo This makes the type of foo.localalias the same as foo, which I gather should placate objtool as it'll still see an STT_FUNC no matter whether it picks up foo.localalias or foo.