From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF46201000 for ; Tue, 29 Oct 2024 05:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730181098; cv=none; b=mY9W6aywEgUFES3x/s7O2eATn1y+LFli7jb+IP+/JHg9ylGEEQzUW+Fu+HjP7uwhVrSfqyhOKiczSUT0XODbh0f3mSJPDOTwztA9PgC6jl1w+aMK7z4q8mymqcUdT4k/SF6atM4JuCPhcqlVsA+nKVVNL0BFaJQp1ZSntsfkMwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730181098; c=relaxed/simple; bh=rkJGzaJiGDNyDHmrzD6Ukn0kvrLRqUNFw7rsJbF66DM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CbUyWXwQHGQzbdTAXXTD5iyV5y5Smi1G4J8n5FPooxeK+P4C7fbYDKOTAOiTlb4httOZSgBCre/e+syOizFnonjT/it1Ogrg2sTEEQ6881VT1fRXzlaRDQDWkKCZl6KTqvcRFHCwnP7dDplrqn1STVUaZMegt/x5c3veFs+dD4I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=O4MXc1dw; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O4MXc1dw" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-460969c49f2so146901cf.0 for ; Mon, 28 Oct 2024 22:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730181095; x=1730785895; 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=yS+AWBnCO/J18Xc6TcuxqR5XEdAGr/Rpio3YV4nA0AE=; b=O4MXc1dwxcgbsQWGK53emGves46j/aC/NBO5mU8uxHNFbMgm99YV1mCvYt9FMmNEza Nrd0l09XgIndpa3N3+rrO40GWHE8PMH7DSRn3APfxUKc4+e+mpNPr5krVYfDQMYaBz23 nH1KKMPj/U8SaZ35spcPGvPCabb5tlab7e/+5XDtZbEyF3Vt2zbgaTjPJRaLBEgdjAW8 aOkTwCEQ+Zcgy00U/n839uEzdgcCnE5gwi3sacJIgOnnSCbV2+TP+4lRbRS1z4BLEBFu y1KDxn2N4Xlmsy+XhzHUd8ZpFcdvQNNezNsYWFO3DJcGqSuqYguNEDUe50pXcQrHwjMI zJqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730181095; x=1730785895; 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=yS+AWBnCO/J18Xc6TcuxqR5XEdAGr/Rpio3YV4nA0AE=; b=uraOSpooS8bBi/tz4onmgZy3ocdnhKB+tIdPmJgWLbA9X95q3rwhe1NTHms8aOMUIg tnv4sp8151i3QixJaeaxtormpdd1PAyXW5YTTy/k31U6Tkp8bWP+i+W1op32HGpPHuww IhjVrHwrViccwL77i1q0wyBOdbx8HM1xS/qxOVlRDvwtdc8qxb7narE06PMW7n+ObOfE U0TN90QwBQf/3vqVDOHShaeQCRmd9XStl1fryQkKH82AVTpfzP4GmYE/EtIUAUyz2CDh 0mKzIkvRrh3RZucx2ct/9XVE5vUfHYn+Q6fPBtGU9I9NOsieJ1z7r4kuno94phgEKr4E qS4A== X-Forwarded-Encrypted: i=1; AJvYcCWthZXmr1pbwswh00en1mBSDNmviEcNVvBAG5SV0p8tfyuYxiu+epfidl5pPV6Sx41x4J1xaROq4Bk=@vger.kernel.org X-Gm-Message-State: AOJu0YzKyBZbxApEPQ/ZHPc/mlQLHF1U11Ho7/N5E+eSF6KHDo8oVVY9 uSA6g1uN6hUecsfWhxm8uhpSjaBhaEWjBxlRz+bInoJ5FWVDxpMSraerR3ukQobQJwUOdzsumVX u/UnNS/fmWg6uKy3PXu1ijeVqmsdmVMRSTNvm X-Gm-Gg: ASbGncuZJQvgZY9ZLrNGQzKunehqP8c91gd5B5+AT+G2lP5xP8knHrdGIIh4Qx/pJdT 95AzQA6xS6L/wx8mMBQdW0/1kC4l5CrcO1oQAMDYGStL2h8YGc3KYEzhBjiw= X-Google-Smtp-Source: AGHT+IEVAXdFG3fNtFOsbcJBNRZwq6dZ7NPHf4Fl17QtrnIba/Ad0eOq8gq9bIFuScwN6QgnbyAorRomVIE9wKpqH3w= X-Received: by 2002:a05:622a:38b:b0:45f:6f3:5671 with SMTP id d75a77b69052e-46164fa2de0mr2424301cf.20.1730181094473; Mon, 28 Oct 2024 22:51:34 -0700 (PDT) Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241026051410.2819338-1-xur@google.com> <20241026051410.2819338-3-xur@google.com> <202410281716.0C8F383@keescook> <0605fa9c-0e48-48ec-b04d-c2ef1c48fdd9@zytor.com> In-Reply-To: <0605fa9c-0e48-48ec-b04d-c2ef1c48fdd9@zytor.com> From: Rong Xu Date: Mon, 28 Oct 2024 22:51:21 -0700 Message-ID: Subject: Re: [PATCH v6 2/7] objtool: Fix unreachable instruction warnings for weak functions To: "H. Peter Anvin" Cc: Kees Cook , Alice Ryhl , Andrew Morton , Arnd Bergmann , Bill Wendling , Borislav Petkov , Breno Leitao , Brian Gerst , Dave Hansen , David Li , Han Shen , Heiko Carstens , Ingo Molnar , Jann Horn , Jonathan Corbet , Josh Poimboeuf , Juergen Gross , Justin Stitt , Masahiro Yamada , "Mike Rapoport (IBM)" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , "Paul E. McKenney" , Peter Zijlstra , Sami Tolvanen , Thomas Gleixner , Wei Yang , workflows@vger.kernel.org, Miguel Ojeda , Maksim Panchenko , "David S. Miller" , Andreas Larsson , Yonghong Song , Yabin Cui , Krzysztof Pszeniczny , Sriraman Tallam , Stephane Eranian , x86@kernel.org, linux-arch@vger.kernel.org, sparclinux@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I think the objtool works on individual object files (or vmlinux.o). The -Wl,--gc-sections flag, on the other hand, is a linker flag that acts on the final link -- it's applied after objtool invocations. Therefore, even with -Wl,--gc-sections, we'll still encounter those spurious warnings from objtool. -Rong On Mon, Oct 28, 2024 at 5:19=E2=80=AFPM H. Peter Anvin wrot= e: > > On 10/28/24 17:16, Kees Cook wrote: > > On Fri, Oct 25, 2024 at 10:14:04PM -0700, Rong Xu wrote: > >> In the presence of both weak and strong function definitions, the > >> linker drops the weak symbol in favor of a strong symbol, but > >> leaves the code in place. Code in ignore_unreachable_insn() has > >> some heuristics to suppress the warning, but it does not work when > >> -ffunction-sections is enabled. > >> > >> Suppose function foo has both strong and weak definitions. > >> Case 1: The strong definition has an annotated section name, > >> like .init.text. Only the weak definition will be placed into > >> .text.foo. But since the section has no symbols, there will be no > >> "hole" in the section. > >> > >> Case 2: Both sections are without an annotated section name. > >> Both will be placed into .text.foo section, but there will be only one > >> symbol (the strong one). If the weak code is before the strong code, > >> there is no "hole" as it fails to find the right-most symbol before > >> the offset. > >> > >> The fix is to use the first node to compute the hole if hole.sym > >> is empty. If there is no symbol in the section, the first node > >> will be NULL, in which case, -1 is returned to skip the whole > >> section. > >> > >> Co-developed-by: Han Shen > >> Signed-off-by: Han Shen > > > > This seems logically correct to me, but I'd love to see review from Jos= h > > and/or Peter Z on this change too. > > > > Reviewed-by: Kees Cook > > > > Does this happen even with -Wl,--gc-sections? > > -hpa >