Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp243736pxb; Fri, 15 Jan 2021 11:52:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNg1pRhh6/aKZdEsN2FZX0xbj/KBqP4E2RcG3q+fOtMfyFa+3ifCnBmMA1E3FY3bgVHxwR X-Received: by 2002:a17:906:99c5:: with SMTP id s5mr9960276ejn.236.1610740356572; Fri, 15 Jan 2021 11:52:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610740356; cv=none; d=google.com; s=arc-20160816; b=B5nW8IP0vjuGadqHIxEzy88wDFqfNvhivFqzZ1tlpzAeF8Cb5AMWXk1xD0+SMzO8fW X+gMiRwBDbpdmGpNQdFjcU+KNGk9Dj69sEPQXHgM60LxYXvkhEfnFmB7XTvNLQWv5RDc 6XX2aOJfXsgNpBzpz+8LYZtK2ucp9JCFCSZL3QaaRACLqcozGpy0fEhcchOZO3dXVd8f VDg0ogzrMti1/dIJ2vwKc9QHgkxJ2RWn4M0rHHgzz/vY+XY2RquJqbfQl703dP2KFKAT SKm8BSz4Egj2av/v6ktH477MHKnZXYTjfrjzGXhx/LX6Wm/SMpW1u08R05BvAZjOG4QM zvUw== 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=PnPuJYU4PXQYlGf79G8ijZzEVP+6toQVVVmd55UETSI=; b=bdhT+wG1/fC7sD4lOIFMTtxyFBGeSqGKFxroy3kA8G1JgjNTWuAfnJYZNJ3Qtulxg9 OZAUR3YTcofysr85OvE+WdU7kW1UbXxvqZHdVjgI1adpoo5Ox/1zNoe3X/4+4vYEqGTw mYAe7G6kbtpUpcEcC8EEgCpVOFqRiyK3ovXrPhASWeq9Qx0uuqDpSj8kU/ICCMc4qjjE eyf/9PWKrBf6iDu5S/WFHob3W5OBw65dMhdIXVOn/UxmehhD1zLDNiBalflucTD4IpEl JgUOV/76p5dNb/GGwVUfL72bQhCDWWINWqS2mXQAxt7HA5htCaS1Tnufz7DQlwm2nekV D1Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XWKvrIeT; 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 t5si4479914edw.52.2021.01.15.11.52.12; Fri, 15 Jan 2021 11:52:36 -0800 (PST) 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=XWKvrIeT; 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 S1729079AbhAOTu6 (ORCPT + 99 others); Fri, 15 Jan 2021 14:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbhAOTu4 (ORCPT ); Fri, 15 Jan 2021 14:50:56 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34F7C061757 for ; Fri, 15 Jan 2021 11:50:15 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id v24so8227880lfr.7 for ; Fri, 15 Jan 2021 11:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=PnPuJYU4PXQYlGf79G8ijZzEVP+6toQVVVmd55UETSI=; b=XWKvrIeTxTf2RNy2JOHnXPqjTI8NmkQqS2QCk2n+lbqfoQXsmL1GCz5kcI9Pnzqx+y jz1lU1nz8wNWF1NyDPI8MIYbNQii0FEkon3Nsh2rS0hH1aAI+obFgELriU13/kjMUXJx 6VBk1TQbUWPF5jFubPVTh6XylOc1/Y0bEBUStlS7tqVdIAZHxMFEZf89+VSJqqKGyJln tCQDjxaLArubOCUB+KeNNcysy1E238kCNIAorjzZIwewxfo1BP9euUxkCuCotT69mX+H 0uZPyOHbu0HQbl5+VwquLIUzkawRHK2scvg6SPU0rD1txsfjZ7zgO6wDClU1KtzC1srL bYFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=PnPuJYU4PXQYlGf79G8ijZzEVP+6toQVVVmd55UETSI=; b=rI9z8VPPFW2PCbK9eZewJRD3pSrOgXEOcxqZBWe7iaJukXR97kcGQujwJ7hW1DNvF+ PPZKu+iYnDkRh2PTVd0E9NV6tr129Gazxpn67nji3PN4vouKJI5+UzADDOWFz/k78wqs FojX+Gw48b6qjU5h5R3ujPGe8IDXR9QzUImCK+DxWqz8PVhwX0Mi8VbJb5MhywW5Es+a XP/Y3y2LZYghuhK6bzKipZFjDJHvQiVaahbAzQBdJ3qKWD+BVlsFSrS+6QPzs1tuxuqk q2d4d9UJMGybSA7vfawT6N8XxPXKFRTamukhD6lPuEo0fSkCi87+wZqtokIIc5a5lvCa +F3A== X-Gm-Message-State: AOAM532BKja8/Peu8fEHeYQN0mWvGBSiDEgl9V50PTnw0e+yof26ExAS ZzOCEi+81iNC1LZKJvQVfDjkVKGbyrqCrKAkZI/rXw== X-Received: by 2002:ac2:593a:: with SMTP id v26mr4310238lfi.591.1610740214143; Fri, 15 Jan 2021 11:50:14 -0800 (PST) MIME-Version: 1.0 References: <20210114211840.GA5617@linux-8ccs> <20210114215416.993167-1-maskray@google.com> In-Reply-To: From: =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= Date: Fri, 15 Jan 2021 11:50:02 -0800 Message-ID: Subject: Re: [PATCH v2] module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols To: Marco Elver Cc: LKML , Jessica Yu , clang-built-linux , Sam Ravnborg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 14, 2021 at 11:04 PM Marco Elver wrote: > > On Thu, 14 Jan 2021 at 22:54, Fangrui Song wrote: > > clang-12 -fno-pic (since > > https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083= 333232da3f1d6) > > can emit `call __stack_chk_fail@PLT` instead of `call __stack_chk_fail` > > on x86. The two forms should have identical behaviors on x86-64 but th= e > > former causes GNU as<2.37 to produce an unreferenced undefined symbol > > _GLOBAL_OFFSET_TABLE_. > > > > (On x86-32, there is an R_386_PC32 vs R_386_PLT32 difference but the > > linker behavior is identical as far as Linux kernel is concerned.) > > > > Simply ignore _GLOBAL_OFFSET_TABLE_ for now, like what > > scripts/mod/modpost.c:ignore_undef_symbol does. This also fixes the > > problem for gcc/clang -fpie and -fpic, which may emit `call foo@PLT` fo= r > > external function calls on x86. > > > > Note: ld -z defs and dynamic loaders do not error for unreferenced > > undefined symbols so the module loader is reading too much. If we ever > > need to ignore more symbols, the code should be refactored to ignore > > unreferenced symbols. > > > > Reported-by: Marco Elver > > Link: https://github.com/ClangBuiltLinux/linux/issues/1250 > > Signed-off-by: Fangrui Song > > Tested-by: Marco Elver > > Thank you for the patch! > > > --- > > kernel/module.c | 20 ++++++++++++++++++-- > > 1 file changed, 18 insertions(+), 2 deletions(-) > > --- > > Changes in v2: > > * Fix Marco's email address > > * Add a function ignore_undef_symbol similar to scripts/mod/modpost.c:i= gnore_undef_symbol > > > > diff --git a/kernel/module.c b/kernel/module.c > > index 4bf30e4b3eaa..278f5129bde2 100644 > > --- a/kernel/module.c > > +++ b/kernel/module.c > > @@ -2348,6 +2348,20 @@ static int verify_exported_symbols(struct module= *mod) > > return 0; > > } > > > > +static int ignore_undef_symbol(Elf_Half emachine, const char *name) > > Why not 'bool' return-type? Will use bool and false in v3. > > +{ > > + /* On x86, PIC code and Clang non-PIC code may have call foo@PL= T. GNU as > > Not sure if checkpatch.pl warns about this, but this multi-line > comment does not follow the normal kernel-style (see elsewhere in > file): It doesn't warn about this. (The commit description warning cannot be fixed, even if I place the closing paren on the next line.) % ./scripts/checkpatch.pl v2-0001-module-Ignore-_GLOBAL_OFFSET_TABLE_-when-warning-.patch WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line) #8: https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de00833332= 32da3f1d6) total: 0 errors, 1 warnings, 32 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplac= e. v2-0001-module-Ignore-_GLOBAL_OFFSET_TABLE_-when-warning-.patch has style problems, please review. NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. > /* > * ... > */ > > > + * before 2.37 produces an unreferenced _GLOBAL_OFFSET_TABLE_ o= n x86-64. > > + * i386 has a similar problem but may not deserve a fix. > > + * > > + * If we ever have to ignore many symbols, consider refactoring= the code to > > + * only warn if referenced by a relocation. > > + */ > > + if (emachine =3D=3D EM_386 || emachine =3D=3D EM_X86_64) > > + return !strcmp(name, "_GLOBAL_OFFSET_TABLE_"); > > + return 0; > > +} > > + > > /* Change all symbols so that st_value encodes the pointer directly. *= / > > static int simplify_symbols(struct module *mod, const struct load_info= *info) > > { > > @@ -2395,8 +2409,10 @@ static int simplify_symbols(struct module *mod, = const struct load_info *info) > > break; > > } > > > > - /* Ok if weak. */ > > - if (!ksym && ELF_ST_BIND(sym[i].st_info) =3D=3D= STB_WEAK) > > + /* Ok if weak or ignored. */ > > + if (!ksym && > > + (ELF_ST_BIND(sym[i].st_info) =3D=3D STB_WEA= K || > > + ignore_undef_symbol(info->hdr->e_machine, = name))) > > break; > > > > ret =3D PTR_ERR(ksym) ?: -ENOENT; > > -- > > 2.30.0.296.g2bfb1c46d8-goog > > --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF