From patchwork Fri Sep 6 10:32:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 11134947 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 250551395 for ; Fri, 6 Sep 2019 10:32:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF30B206CD for ; Fri, 6 Sep 2019 10:32:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Skz33sHp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391998AbfIFKcu (ORCPT ); Fri, 6 Sep 2019 06:32:50 -0400 Received: from mail-vk1-f201.google.com ([209.85.221.201]:49875 "EHLO mail-vk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391958AbfIFKct (ORCPT ); Fri, 6 Sep 2019 06:32:49 -0400 Received: by mail-vk1-f201.google.com with SMTP id j8so2215736vkn.16 for ; Fri, 06 Sep 2019 03:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WpyyM8zjm4wtK5J690VZrM2s4HSiRGUxtkfpxo7zqKI=; b=Skz33sHpPCZnoHy3AvVrg/LLqwQwyEGz36anNkWQoU5roRNbtVs5HkCrAJzloD84GS FLXgT091RDmDDpkiFmgCVdrhxFh4kkwp/pxul1aUfuCd947ZNUFsfhjERMj7Cs7koVX0 qWq3tCWdb9YWHwMxMI2hoEuadpcMBD3K5HPm5XCXLz/+Tx0QBEhvO59ElSqBGHqhgWVP vvw4IHRL1YGoIDpc+Ct+u2nvyGtLyZJGuviNOpHBItO2gMnzAZDevmP4oRFE7P46vTni fUh41ilsp4v3ceWjwKRPEZzgn6/oYJOGhl2jFZWF/019eio/TcnBj+J3z2ztgxL66/Z+ 5j0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WpyyM8zjm4wtK5J690VZrM2s4HSiRGUxtkfpxo7zqKI=; b=IyG7mADKdihGQjJ9Afx+31tCHJQ4vt7Gw//IhzEta9GM9Imx9vRAVjON3KjEi/Nken cQXT98ohqL61r//usRVQzEU5Lh9Alx6AB1Nok8lNbozl6YqCSVi1Fd7Cm+ivQ9iA7ur4 5ThI+Nj4odK+0YA6XqFLdamnbbMcH2HBcCKZgakMS3DdO0hBOaio5ffEu0o6sv4h3v5I LpR7G27Hz4wVwL8XJt6I311i19SjGU1V9/toAvuVZiYWKG7K/Ti0pX2UNmApmtEhyURs 1byuEmB4M/rYAd6netJ+A5Cyl1oMgK1QYKGWnkQqspsFVw/rvYdlH1iWrULkLO54MfuZ vtsA== X-Gm-Message-State: APjAAAVcDT5wun4wOcuMFLXlhiMjfrZOk8dEwrpBv7YSVwjzvnJTCNYy a7kOuM0Q1TeDxzndNP7uEvl+P1uypMVzmg== X-Google-Smtp-Source: APXvYqwji9IO4P0sdnEEwGtqAmxa5gZ9mhcJuZTmoabFbDwxSe1f5uRwH8hIxTnlZWVDVEHc/tFE2bzrgk+OgQ== X-Received: by 2002:a67:1687:: with SMTP id 129mr4598055vsw.232.1567765968027; Fri, 06 Sep 2019 03:32:48 -0700 (PDT) Date: Fri, 6 Sep 2019 11:32:26 +0100 In-Reply-To: <20190906103235.197072-1-maennich@google.com> Message-Id: <20190906103235.197072-3-maennich@google.com> Mime-Version: 1.0 References: <20180716122125.175792-1-maco@android.com> <20190906103235.197072-1-maennich@google.com> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog Subject: [PATCH v5 02/11] export: explicitly align struct kernel_symbol From: Matthias Maennich To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, maennich@google.com, arnd@arndb.de, gregkh@linuxfoundation.org, jeyu@kernel.org, joel@joelfernandes.org, lucas.de.marchi@gmail.com, maco@android.com, sspatil@google.com, will@kernel.org, yamada.masahiro@socionext.com, linux-kbuild@vger.kernel.org, linux-modules@vger.kernel.org, linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This change allows growing struct kernel_symbol without wasting bytes to alignment. It also concretized the alignment of ksymtab entries if relative references are used for ksymtab entries. struct kernel_symbol was already implicitly being aligned to the word size, except on x86_64 and m68k, where it is aligned to 16 and 2 bytes, respectively. As far as I can tell there is no requirement for aligning struct kernel_symbol to 16 bytes on x86_64, but gcc aligns structs to their size, and the linker aligns the custom __ksymtab sections to the largest data type contained within, so setting KSYM_ALIGN to 16 was necessary to stay consistent with the code generated for non-ASM EXPORT_SYMBOL(). Now that non-ASM EXPORT_SYMBOL() explicitly aligns to word size (8), KSYM_ALIGN is no longer necessary. In case of relative references, the alignment has been changed accordingly to not waste space when adding new struct members. As for m68k, struct kernel_symbol is aligned to 2 bytes even though the structure itself is 8 bytes; using a 4-byte alignment shouldn't hurt. I manually verified the output of the __ksymtab sections didn't change on x86, x86_64, arm, arm64 and m68k. As expected, the section contents didn't change, and the ELF section alignment only changed on x86_64 and m68k. Feedback from other archs more than welcome. Co-developed-by: Martijn Coenen Signed-off-by: Martijn Coenen Reviewed-by: Greg Kroah-Hartman Signed-off-by: Matthias Maennich --- arch/m68k/include/asm/export.h | 1 - include/asm-generic/export.h | 8 +++----- include/linux/export.h | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/m68k/include/asm/export.h b/arch/m68k/include/asm/export.h index 0af20f48bd07..b53008b67ce1 100644 --- a/arch/m68k/include/asm/export.h +++ b/arch/m68k/include/asm/export.h @@ -1,3 +1,2 @@ -#define KSYM_ALIGN 2 #define KCRC_ALIGN 2 #include diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index 294d6ae785d4..63f54907317b 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -4,15 +4,13 @@ #ifndef KSYM_FUNC #define KSYM_FUNC(x) x #endif -#ifdef CONFIG_64BIT -#ifndef KSYM_ALIGN +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +#define KSYM_ALIGN 4 +#elif defined(CONFIG_64BIT) #define KSYM_ALIGN 8 -#endif #else -#ifndef KSYM_ALIGN #define KSYM_ALIGN 4 #endif -#endif #ifndef KCRC_ALIGN #define KCRC_ALIGN 4 #endif diff --git a/include/linux/export.h b/include/linux/export.h index fd8711ed9ac4..28a4d2150689 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -52,7 +52,7 @@ extern struct module __this_module; #define __KSYMTAB_ENTRY(sym, sec) \ __ADDRESSABLE(sym) \ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \ - " .balign 8 \n" \ + " .balign 4 \n" \ "__ksymtab_" #sym ": \n" \ " .long " #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \ @@ -66,6 +66,7 @@ struct kernel_symbol { #define __KSYMTAB_ENTRY(sym, sec) \ static const struct kernel_symbol __ksymtab_##sym \ __attribute__((section("___ksymtab" sec "+" #sym), used)) \ + __aligned(sizeof(void *)) \ = { (unsigned long)&sym, __kstrtab_##sym } struct kernel_symbol {