Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2386379rdb; Thu, 21 Sep 2023 18:07:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4nvxnGnowGSh8TMGUkJTnmxmsBEOcoF7cl21/zjfCI2VI6HQIatGIcR736YdPVBrov7qe X-Received: by 2002:a17:902:82c4:b0:1c3:758d:32de with SMTP id u4-20020a17090282c400b001c3758d32demr6927969plz.12.1695344842790; Thu, 21 Sep 2023 18:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695344842; cv=none; d=google.com; s=arc-20160816; b=M/tgnWKX/F7DYtnxQ2TzyHpMSUWFqG9UAoxM5BVxNp14hRmPWqZrxyh2+PrrFcTBym ssb5fCLM+IoBMeb286V1qdx9hxeXN8qKj+MSmoVW9OBzouOZCjri6JbG4MJUXWUD+GMu 5T08N/wSG+7qgX23jZNhZyr3WCFfpXZAI1MjIUWcokT9IxVFO60rGWVws96JRNe04o6E yqRcz5aBQBmizYUBYF2YMjxbB6k/JgiZzutlh9NSfonbEr0IyndBX6qBr4MyUaAws5Hr 6txFOIlikoejsWVVgsWeeQmzESHpIuKkowMIvH9FLcb48Py7+CRh4DI/uu+K18ZcO74k QsOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=b2rhuVc5nDe//8n4ZYcZiDm+U/AGb9s4mBHSicI1GSU=; fh=FhmsxNZKN2NY1ofs2e4wzr2QnhLz9jg8/P8RnHBDvJk=; b=K+0kclcx5qEGnhmCZ/piwG3zoSMrMKne48gtzD3QD8M2deNDQvODbMfeBMb6zPTIQ/ V62R7q0thUQTw/7ep71uCi5J7zz2KtDEwT0STIYp4c/MVfQnhPcPzLpcidIoj2ALPv6B zhUbBRxmqbhb6832SxjoF48YOKnpwQFeE15DXYJgrLnwrpYQqRiB+6IV3K2nm1IXOyDD Q4YfvRIsptZhscIer5DEgs8xTN6mnSrfuqaQCyFq3ldBN1lC4haUVel0RBRjYHdHPFF8 5b7BrBRi2YQ8whOJMmjylrWpe05zTe5iW8vbj73ah+vWVOTtp8ek6YJaXP3LPZ4EkKgm BMJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KXcVOliK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z6-20020a170902d54600b001c59b6ed118si2763401plf.157.2023.09.21.18.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 18:07:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KXcVOliK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6D8708246953; Thu, 21 Sep 2023 13:01:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbjIUUBY (ORCPT + 99 others); Thu, 21 Sep 2023 16:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbjIUUAw (ORCPT ); Thu, 21 Sep 2023 16:00:52 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CF36101A8 for ; Thu, 21 Sep 2023 10:30:04 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c382f23189so12785ad.0 for ; Thu, 21 Sep 2023 10:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695317397; x=1695922197; darn=vger.kernel.org; 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=b2rhuVc5nDe//8n4ZYcZiDm+U/AGb9s4mBHSicI1GSU=; b=KXcVOliK0C28HKNXNLsMoYaaB/NzIZWBQg185Wd+Br038cWTT4P0ZjYVj9aPY8jzpg MvfpxtPVj4/QaSEje7FROcodnuUQYQJgFmD4UDEZBuJLtSQUPhAqaL1BNdVWbrOVbuEd IR+huad0dWiKg+ph565KOJ0yThD3PZ/uhn2fOBtLykfS102yXmdAd4TCJOEtV3GFDuc0 edRjKRFEecv3usN8wZo35GVEVXPdEhqApdvLIiRM2MKEfcPkT+v7pys30/fBcKkHKQKw Y/ti0W126yvxvTBH9cbk4u5cZD/gRGFXPtcK9z0ZYlBKw0WoAv4uybraZCSoMfuvCjj8 cBIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695317397; x=1695922197; 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=b2rhuVc5nDe//8n4ZYcZiDm+U/AGb9s4mBHSicI1GSU=; b=dlXpwB3lmFZhDSLXmTffdyreGn+7mBoqDGwvwMa74usievNl/yyZBg1wvHgLvZgjdN CJRfpCEaq/wc40l4+/VDV/RQq+fRUXTuIifw4xfYGo4cYST7RtsaHqm9dTuIYStSlbSe 15Lm4OV3b96q04M95hxvuAKKld4MttuEptqyjidMj35jw4mes55vGMl8ZNplkQTGc5vW enHdJtRL6sQfDaTAfYLmd5o71sqi8u/t+KedMVSeKqXh2YTrqa4HLG/iQvLoq27OXraV +H17cdgl1hpNBM+hm8Ep0TY7+vhU/GhZBLpgichBoQTNbouIR46a7uW45t6Z5YC/kAxI sK7w== X-Gm-Message-State: AOJu0YwnLBhwWopfYoC2febMN9LtLLnCyPL6sOgfJvhfEmfx7T99bZwo OYjinNVnNI5SzRQFEV5WVQYzrC6+c3q41gdHyDcD45WTx1VsF1pt8TApRg== X-Received: by 2002:a05:622a:1341:b0:417:9045:50c9 with SMTP id w1-20020a05622a134100b00417904550c9mr303608qtk.22.1695313614576; Thu, 21 Sep 2023 09:26:54 -0700 (PDT) MIME-Version: 1.0 References: <20230920001728.1439947-1-maskray@google.com> <20230921072655.GA14803@noisy.programming.kicks-ass.net> <20230921153537.GG14803@noisy.programming.kicks-ass.net> In-Reply-To: <20230921153537.GG14803@noisy.programming.kicks-ass.net> From: Fangrui Song Date: Thu, 21 Sep 2023 09:26:43 -0700 Message-ID: Subject: Re: [PATCH] x86/speculation, objtool: Use absolute relocations for annotations To: Peter Zijlstra Cc: x86@kernel.org, Josh Poimboeuf , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:01:28 -0700 (PDT) On Thu, Sep 21, 2023 at 8:35=E2=80=AFAM Peter Zijlstra wrote: > > On Thu, Sep 21, 2023 at 12:58:13AM -0700, Fangrui Song wrote: > > On Thu, Sep 21, 2023 at 12:26=E2=80=AFAM Peter Zijlstra wrote: > > > > > > On Tue, Sep 19, 2023 at 05:17:28PM -0700, Fangrui Song wrote: > > > > .discard.retpoline_safe sections do not have the SHF_ALLOC flag. T= hese > > > > sections referencing text sections' STT_SECTION symbols with PC-rel= ative > > > > relocations like R_386_PC32 [0] is conceptually not suitable. Newe= r > > > > LLD will report warnings for REL relocations even for relocatable l= inks > > > > [1]. > > > > > > > > ld.lld: warning: vmlinux.a(drivers/i2c/busses/i2c-i801.o):(.dis= card.retpoline_safe+0x120): has non-ABS relocation R_386_PC32 against symbo= l '' > > > > > > What, why ?!? Please explain more. > > > > This can be read as a pedantic warning from the linker. > > > > A location relocated by an R_386_PC32 relocation in > > .discard.retpoline_safe records an offset from the current location > > (non-allocable) to an text symbol. > > This offset is conceptually not suitable: in the ELF object file > > format's model, the non-SHF_ALLOC section is not part of the memory > > image, so > > we cannot say that the offset from the non-memory thing to a text > > symbol is a fixed value. > > Bah, so why has this worked at all then? Clearly the linkers aren't very > strict about things. GNU ld isn't very strict, but LLD has had a warning for non-relocatable links for a long time (https://github.com/llvm/llvm-project/blob/main/lld/test/ELF/non-abs-reloc.= s). LLD just did not report warnings for relocatable links. > Anyway, I think what we want is to just mark the section SHF_ALLOC. The > reason is that one of the plans we have is to collapse all the different > annotations into a single section and then have something like: > > struct objtoo_annotation { > s32 location; > u32 type; > } > > So that we can easily extend the annotations and don't need to add > yet-another-section-reader-function to objtool. > > This is just one of the things we've not gotten around to yet. But as > is, we have: > > .discard.unreachable > .discard.reachable > .discard.func_stack_frame_non_standard > .discard.ignore_alts > .discard.unwind_hints > .discard.noendbr > .discard.retpoline_safe > .discard.instr_end > .discard.instr_begin > .discard.validate_unret > .discard.intra_function_calls > > And with the exception of unwind_hints, they're all just trivial > location things. > > The very last thing we need is yet more of that. If these sections are guaranteed to be discarded (*(.discard.*) in scripts/module.lds.S and include/asm-generic/vmlinux.lds.h), using non-SHF_ALLOC sections isn't a bad choice. The intention is actually clearer. > If we were to use absolute things, we get 12 byte entries and while that > probably wouldn't spell the end of the world, why make thing larger than > they have to be. > > After all, its not like any of this actually survives the final link. I do not see why absolute things need 12 byte entries. We can freely use `.long .text.foo` even in ELFCLASS64 object files. There is no risk of overflow (the ultimate link .text.foo may have an address of 0xffffffff........) since the section will be discarded. Referencing SHF_ALLOC sections with absolute relocations in non-SHF_ALLOC sections has well-defined semantics, as used by .debug_* sections. --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF