From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id B3B8D3858D33 for ; Thu, 11 May 2023 06:08:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3B8D3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-619be7d7211so38221566d6.3 for ; Wed, 10 May 2023 23:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683785292; x=1686377292; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uxgk7WXGwyr4fRRANws+EIJa8U14HTzZlYfsbPvcDg0=; b=COzp+VoPi8Cqi1hHuQp6spm+RtxlAH9qjTr3VuJ+1tkxGTOE1oOv7MLI0Jw3BrEjjj 438A7mPnPa/knCrRTjB2k8WwpJh4HD/o5CEYvbLCaTKBomz4Fleyjswt54hQ+PM+RN8+ 1lRQrJayOjvHQpWWX3URccSGywSRp70Jj8DdScF34dikp9La331JvSGPKjNGIaDAsQec 3AzpK+pis1wm8yotyFQL3MAIljhkoziw4HNdBndYGGENxacSys9oD/nwd73CzutPwETP Gh7pzXAl3tasGFzPmetojTlit4rs8GVIQJucv2PxCK/GLKkgpLIore9PkYzu0Biks7mj RNUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683785292; x=1686377292; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uxgk7WXGwyr4fRRANws+EIJa8U14HTzZlYfsbPvcDg0=; b=gVLENMJaWI4EH1A5/cM90/Z97rldjnxShaW112RddkiH2TqYgW6PkHq66h+Nj86ex5 L84yukB/JIJrPIhhrFMoCDS3EfeBWxnrvdLHv75JGhXKKWP8b4Mpiw5Ypuxz0MpgzGke m27/m9DaOS9a5u3yS06a6WjRuJ+ol5Wq0trQoof0avAfusdwU0+vTZYz4rNX2mV4PZH3 c71dQRq+yFbe4XmlZFMM4SoAR75JgcKsXAjeYixa36Oxb8lvkFoZE75E9sQGNzNF4rN+ f7014ppXDeBE2etIzmN8mwfoLlb6b1fWM2PPo3TmvJFwxNcONBVCXxgdbLlx6UQaJs6h 4W+Q== X-Gm-Message-State: AC+VfDxgCf5yzsJ60zf8A2AdNKkdHpu25hd9qvr2KrbXaMU6Puuo6Zz1 WF+h7Me08bDxH0SyemIue2/IB6HCHvdaMhzpoH8= X-Google-Smtp-Source: ACHHUZ6DISVj3+int9HPJzcBff0Z+CrFbIWhQKEUAUV4u9iLZDFjzXVYdRAZL7JJNdgZPP/28w0OVAtzwsG4q4qb+LQ= X-Received: by 2002:a05:6214:2301:b0:616:7a62:a7d0 with SMTP id gc1-20020a056214230100b006167a62a7d0mr30693352qvb.16.1683785291984; Wed, 10 May 2023 23:08:11 -0700 (PDT) MIME-Version: 1.0 References: <20230509085835.1143661-1-ardb@kernel.org> In-Reply-To: From: Uros Bizjak Date: Thu, 11 May 2023 08:08:01 +0200 Message-ID: Subject: Re: [PATCH] i386: Honour -mdirect-extern-access when calling __fentry__ To: "H.J. Lu" Cc: Ard Biesheuvel , gcc-patches@gcc.gnu.org, keescook@chromium.org, Jakub Jelinek , Richard Biener , Hou Wenlong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, May 11, 2023 at 12:04=E2=80=AFAM H.J. Lu wrot= e: > > On Wed, May 10, 2023 at 2:17=E2=80=AFAM Uros Bizjak w= rote: > > > > On Tue, May 9, 2023 at 10:58=E2=80=AFAM Ard Biesheuvel wrote: > > > > > > The small and medium PIC code models generate profiling calls that > > > always load the address of __fentry__() via the GOT, even if > > > -mdirect-extern-access is in effect. > > > > > > This deviates from the behavior with respect to other external > > > references, and results in a longer opcode that relies on linker > > > relaxation to eliminate the GOT load. In this particular case, the > > > transformation replaces an indirect 'CALL *__fentry__@GOTPCREL(%rip)' > > > with either 'CALL __fentry__; NOP' or 'NOP; CALL __fentry__', where t= he > > > NOP is a 1 byte NOP that preserves the 6 byte length of the sequence. > > > > > > This is problematic for the Linux kernel, which generally relies on > > > -mdirect-extern-access and hidden visibility to eliminate GOT based > > > symbol references in code generated with -fpie/-fpic, without having = to > > > depend on linker relaxation. > > > > > > The Linux kernel relies on code patching to replace these opcodes wit= h > > > NOPs at runtime, and this is complicated code that we'd prefer not to > > > complicate even more by adding support for patching both 5 and 6 byte > > > sequences as well as parsing the instruction stream to decide which > > > variant of CALL+NOP we are dealing with. > > > > > > So let's honour -mdirect-extern-access, and only load the address of > > > __fentry__ via the GOT if direct references to external symbols are n= ot > > > permitted. > > > > > > Note that the GOT reference in question is in fact a data reference: = we > > > explicitly load the address of __fentry__ from the GOT, which amounts= to > > > eager binding, rather than emitting a PLT call that could bind eagerl= y, > > > lazily or directly at link time. > > > > > > gcc/ChangeLog: > > > > > > * config/i386/i386.cc (x86_function_profiler): Take > > > ix86_direct_extern_access into account when generating call= s > > > to __fentry__() > > > > HJ, is the patch OK with you? > > LGTM. OK then. Thanks, Uros.