Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3827059pxf; Mon, 22 Mar 2021 16:46:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz27xvINcqilTppFv0tBxuqSr4HD3vKEY35as8dmtcjF92lFu0bm8OpKUPkoKz1/pc3OirQ X-Received: by 2002:a05:6402:520b:: with SMTP id s11mr2036466edd.212.1616456801501; Mon, 22 Mar 2021 16:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616456801; cv=none; d=google.com; s=arc-20160816; b=GYkEs5s+WbHNRWCLTqdYUnC15pBrePJ6Qwck8LbNtlEuB6Z5G47wxgx7SgBtCJggar 84/HhNqeQFFp2nJFtuBDriMG5GXgd9I/jRhDWY7eEWsrH6YGHE0QrX9C2YxS2Qe1/vhO yARr6+7gKGm6vObh7CHDtTvAUhAlnJB3SGn3xJPmbun7Rbpr4dcBE3YgqRDVeRL7L2Zj 3uCSjdGh1GtW0R7jprgySHPoUucEVjb6Q4KCcfzlW9b+BPei1VNKjhCIGYu555YXquye u6efg9ba2QYIwajZ6Qf+qMw3yd3XOgAB8E80jitcpU/IYG4H0jhy+UZPSMtS/L9gvQqw /m1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :reply-to:dkim-signature; bh=4TMeCx7PwkG6nkmerFyzBkQS77hoZyQHillLYYdKYwA=; b=L+ec9sAxuuaIxrjVjS9QFa+F3Ju//EYBZdI8/lizmPhKH7FrHQObIIowJ7yKZFG33x 4xpR1+Agm3lVUzS3kh0AfTwLjNQG4yJxgFRi6cl5CmFFk/defBQk15o8SnQLxkbOqfk4 ycPsAHH5GEpBQCv2EJU9lPlJq1rHCt9C/SPt3LNAgHV5/FqNmd5JHBxbnwCdM9UIb+rs AV6iSSFSs8B+XuxStwGdKUYrbMVng1gVnKRau38wneV32VkQ9vKkj6Y5rT+C1n7/he1y nZFwx1RYbjzuj5DDNLDrDo4YbEKTcq3w/L4/CSSE2uAhONnUdmf0WWWzK4THfM9wq5LX /qTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ph9FImDe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si12648468eja.156.2021.03.22.16.46.18; Mon, 22 Mar 2021 16:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ph9FImDe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230095AbhCVXpJ (ORCPT + 99 others); Mon, 22 Mar 2021 19:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbhCVXon (ORCPT ); Mon, 22 Mar 2021 19:44:43 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E985C061574 for ; Mon, 22 Mar 2021 16:44:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id v6so875165ybk.9 for ; Mon, 22 Mar 2021 16:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:message-id:mime-version:subject:from:to:cc; bh=4TMeCx7PwkG6nkmerFyzBkQS77hoZyQHillLYYdKYwA=; b=ph9FImDeVUGo3wuAvsPknHMCieqw2hI3/S+q6n50uflOiaEPNBe05uDAE7kFNn4jMk bslhQ5oTGPupwdTdkV/X4CWSAWZirDWwqsjuNeu1542GMRSQb8PitcUzfvaAFU5g1lJQ pj548mJ2Vvk4voGR+Rr9A4K9nn28lc96/a2P2BHykDzRmge8cLScVku+RrHRvHL7oOO2 8VNXsbf2d3RI8mEIczmdtbXvPf+PDHsmhbpmPn8fyE9xzZXBvDde+aun+eH0wFCJmUbM Aq/cYKz6Cd3wTMJOPdskSN954OkOLReBmESUMsTbUjs1lpwGtRrWpKxWknY1Gj83HVP6 Y8tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:message-id:mime-version:subject :from:to:cc; bh=4TMeCx7PwkG6nkmerFyzBkQS77hoZyQHillLYYdKYwA=; b=IUkjfnwI8tLcxEoISSi3p1drQU4iteoj8tvta3xaBF3SlSy7148qHCu4FvFjt1YWww t3lIvpUMDfAjGBYLE+HIuJIsWphWilqi9Gm94RLHzvrBPmSUFaFmeaB6jIVue0xXk27V 9ZFhNNtfW00tLs8WcwnkuMg2fmaR7sEi4hzMLI2WCxn+3+EhkUEDBYtl5RgIsGfnUFim zsoEEZ4WRIzzY8A98fEfATyZ42orG+Xqfy9lo3YdyPiQ00BqffCnPzWk+prUciXkCrPN kVRZYzs80G4ZktKGUSS/iQH6llVZKT/p8kMHIRpP4JQacZ+EA73YnTEtFPpdcyEzyp0X zDsQ== X-Gm-Message-State: AOAM530BB91rBqf+u8sJGQk1L8FGQLdSilerM1c42ZqZGuxWg7YUVQlA wlU2+8nQ1jtTOaJnHBOtoMqS0tRj+ac= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:f8cd:ad3d:e69f:e006]) (user=seanjc job=sendgmr) by 2002:a25:745:: with SMTP id 66mr1404929ybh.195.1616456681283; Mon, 22 Mar 2021 16:44:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 22 Mar 2021 16:44:38 -0700 Message-Id: <20210322234438.502582-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH] kbuild: Merge module sections if and only if CONFIG_LTO_CLANG is enabled From: Sean Christopherson To: Masahiro Yamada , Michal Marek , Nathan Chancellor , Nick Desaulniers Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Sami Tolvanen , Kees Cook , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Merge module sections only when using Clang LTO. With gcc-10, merging sections does not appear to update the symbol tables for the module, e.g. 'readelf -s' shows the value that a symbol would have had, if sections were not merged. The stale symbol table breaks gdb's function disassambler, and presumably other things, e.g. gdb -batch -ex "file arch/x86/kvm/kvm.ko" -ex "disassemble kvm_init" reads the wrong bytes and dumps garbage. Fixes: dd2776222abb ("kbuild: lto: merge module sections") Cc: Nick Desaulniers Cc: Sami Tolvanen Cc: Kees Cook Signed-off-by: Sean Christopherson --- This is obviously the quick and dirty approach to fixing the problem, presumably there is a way to actually update the symbols, but that is far, far outside my area of expertise. IIUC how the disassemblers work, the section headers are correctly updated, e.g. objdump displays the correct info, and even gdb's disassembler shows the "correct" offset, it's just the symbol tables that are out of whack. An earlier version of the LTO series did have exactly this #ifdef, but it was dropped when no one objected to Kees' suggestion to unconditionally merge sections. https://lkml.kernel.org/r/202010141548.47CB1BC@keescook scripts/module.lds.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/module.lds.S b/scripts/module.lds.S index 168cd27e6122..3580c6d02957 100644 --- a/scripts/module.lds.S +++ b/scripts/module.lds.S @@ -25,6 +25,7 @@ SECTIONS { * -ffunction-sections, which increases the size of the final module. * Merge the split sections in the final binary. */ +#ifdef CONFIG_LTO_CLANG .bss : { *(.bss .bss.[0-9a-zA-Z_]*) *(.bss..L*) @@ -41,6 +42,7 @@ SECTIONS { } .text : { *(.text .text.[0-9a-zA-Z_]*) } +#endif } /* bring in arch-specific sections */ -- 2.31.0.rc2.261.g7f71774620-goog