From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51204101E6 for ; Thu, 28 Nov 2024 00:57:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732755422; cv=none; b=dpmZ8c/AM9q39vq8XI7l2R2x8cGzI/zPhKWQ4jYt7WHRXeZxDKAYSYRvE1WzPonLlro3VMEsDe4T+5LLYPOCDtaF8OOfMbuFg3aWY1CkkgoBJg38YsPhwEJZWJCsr6Gek2rZpUMircMNyF7Rygr7vhdTDWlhPnRCeeXqbfjQ5Zo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732755422; c=relaxed/simple; bh=vs6YXMnxVt6ZuO2IeY6OKd6OXD6JflY5mqVHPDRj7lg=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: In-Reply-To:Content-Type:Content-Disposition; b=GGJe7XGGcxyqO/iqDF0U4I/5dACePOLLBB0dAZiv/DtcsbBsscbatBb0tcy8/qrxfdEVAIdVsu6KWlUaq9+WwT594nCU98+J9gt28qIR+67Ugzt4YMSsUP8KqxdtyN3RstOAdEt1Z2H2p6tHqpP/7ACTLBhOY5IvHyh1Z5cZPZw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=e2BH+OQE; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e2BH+OQE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732755419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3M5NXT5NgYcv7o/jCn6O1ltoqUkEXIHN0lrzxbItZPY=; b=e2BH+OQELUCneetGpm7axEAv/6UEu6bFG+DlRePFRUj/lYpdIfuCvA8xDUpqVs+Eyb9i5R UCw7trXsRTGxjLm4jssZNX/PphJtjM6ZTNtJ9uU3B6iaj9sPM5r58X3C2ZnMuu5Hryxb4Y JHJpLG06BazYl5OtnQOgsC4736cIcs8= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-223-ECada-fWPOmkn7lPaFnZiw-1; Wed, 27 Nov 2024 19:56:58 -0500 X-MC-Unique: ECada-fWPOmkn7lPaFnZiw-1 X-Mimecast-MFC-AGG-ID: ECada-fWPOmkn7lPaFnZiw Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-841a4a82311so19377239f.2 for ; Wed, 27 Nov 2024 16:56:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732755417; x=1733360217; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3M5NXT5NgYcv7o/jCn6O1ltoqUkEXIHN0lrzxbItZPY=; b=WrmTP3NF8ah9Vqj5a/XXs0ga4kMgQkJ5lXMKyclDXt1G0LBXGqGskP838YFFvJGBhW MsLrFEPDOfH3+OWDyzA2g1OmhBBXh3YmP6FKU4zFa4BYfpPuTlEHBSbTJCTGutxr7rgt uCXmwhuutEpfbrzcB3uTNtCPKzS4YnA3xJodygUUC9jckNEbOEhObcnHws0SiX+kaCxS +tke7JCQzvy1JJtatpNvRrjYZEVcmiDh0PrWrCw43aLUEyzk5rhhRJx52uoVD4akr35Z oonKfQ7S4HZU8qUaT/52x9J3+3TCWand7j0IfnpjPwBIhIwEuM9X7vNYGqxtneQTj+cA xIOQ== X-Forwarded-Encrypted: i=1; AJvYcCXtI6is3dEZpg3PbfNQP0Qgb4A5LiSfzAtUEIL8hug8/OIU1arxBb4MTz3UgPx2PVc/s2A773Ku62/j7Q2Im1Su@vger.kernel.org X-Gm-Message-State: AOJu0Yy2knA7cHpgMSJTmqsUJX2dSzBZv2tsEcJm/6oRm526LuNy+ZZi DYnhdzZ8UPBl79aJTFesdjRfIGWLNlodddN3pQ+HgzrPAhjI+lWlKxCYfm8VaLQU1mV4pftOAZV Zg7BeL7WcyEzftVnCYa04DLscsHzTPyWpy9y1WKQ8QRDVqyOtLyArPj7xIT0+2zJuz1c= X-Gm-Gg: ASbGncvA3U18gwNeqCiKpk2kUwShEeSVg/5FmYamJWYf7MYaLiSbH246QE+QPScXBC0 NSTg/WcErfIWaHY660cqYYjudq4XcGfFPf8UAoXjWpKGUqXjdppZz29iQDngiyHSZW7UavnPrnD LByQDsjlSPC83zoW3oaVZw7defZYIVbywPgUjWUjWihFil3KOGND0PKm+FZGC6tbF+7itBc/4CS 5l1qqGlH/ciJ4bHec/EIDEaisJm X-Received: by 2002:a05:6e02:1689:b0:3a7:20d5:8157 with SMTP id e9e14a558f8ab-3a7c556318dmr49585525ab.11.1732755417413; Wed, 27 Nov 2024 16:56:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3OUPVfIS+/L/sPPeAdCxXP7P6uumIqlNzsg8OI4AY+2yONPmztCAgPhLuzEUCMU+Gnm5xTw== X-Received: by 2002:a05:6e02:1689:b0:3a7:20d5:8157 with SMTP id e9e14a558f8ab-3a7c556318dmr49585275ab.11.1732755417126; Wed, 27 Nov 2024 16:56:57 -0800 (PST) Received: from jpoimboe ([2600:1700:6e32:6c00::1e]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e230e5f229sm54157173.82.2024.11.27.16.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 16:56:56 -0800 (PST) From: Josh Poimboeuf X-Google-Original-From: Josh Poimboeuf Date: Wed, 27 Nov 2024 16:56:53 -0800 To: Ard Biesheuvel Cc: Nick Desaulniers , Tiezhu Yang , Xi Ruoyao , Peter Zijlstra , Huacai Chen , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-toolchains@vger.kernel.org, Jan Beulich , "Jose E. Marchesi" , Kees Cook Subject: Re: annotating jump tables (Re: [PATCH v2 5/5] LoongArch: Enable jump table with GCC for objtool) Message-ID: <20241128005653.st7xwkv2gry2chlc@jpoimboe> References: <20241105123906.26072-1-yangtiezhu@loongson.cn> <20241105123906.26072-6-yangtiezhu@loongson.cn> <20241105141530.GE10375@noisy.programming.kicks-ass.net> <62df4c24-68ed-fbfc-ed98-2df796697d89@loongson.cn> <9589c5b673f45f02e2b0fa9d9a96eff0f0df0920.camel@xry111.site> <7e8adb0b-e681-72ae-40d8-740dc3f9480b@loongson.cn> <20241113211119.lfwlxv2bjyqfqeh2@jpoimboe> Precedence: bulk X-Mailing-List: linux-toolchains@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4JLhyf2JpwomTO3CCzXNbH9mrO_rkkmnKaSaXaxAvmM_1732755417 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Thu, Nov 14, 2024 at 07:13:18PM +0100, Ard Biesheuvel wrote: > > Looks like this was added to clang in: > > https://github.com/llvm/llvm-project/pull/102411 > > > > A comment in llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp > > describes the scheme: > > + // Emit an additional section to store the correlation info as pairs of > > + // addresses, each pair contains the address of a jump instruction (jr) and > > + // the address of the jump table. > > > > Ard had a prototype in: > > https://github.com/llvm/llvm-project/pull/112606 > > which used relocations rather than a discardable section. > > Thanks for the cc. > > I haven't followed up yet because doing this generically is not > straight-forward. The main issue is that AArch64 jump tables could be > emitted into .text with scaled offsets, e.g., > > adr x16, .Ljumptable > ldrb w17, [x16, xN] // xN is the lookup index > add x16, x16, w17, sxtw #2 // x16 += 4 * x17 > br x16 > > .Ljumptable: > .byte (dest0 - .Ljumptable) >> 2 > .byte (dest1 - .Ljumptable) >> 2 > .byte (dest2 - .Ljumptable) >> 2 > .byte (dest3 - .Ljumptable) >> 2 > > So just emitting a relocation at the call site and a symbol covering > the jump table might work for x86, but if we want some that works in > general, we'll have to come up with some format that describes in more > detail how to infer the potential destinations of an indirect call it > is known to be a limited set at compile time. Loongarch is emitting an array of (insn_ptr, jump_table_ptr) tuples in .discard.tablejump_annotate. Would that work more generically? Even better it would also emit the jump table size. -- Josh