diff mbox series

[v9,06/16] kbuild: lto: add a default list of used symbols

Message ID 20201211184633.3213045-7-samitolvanen@google.com (mailing list archive)
State New, archived
Headers show
Series Add support for Clang LTO | expand

Commit Message

Sami Tolvanen Dec. 11, 2020, 6:46 p.m. UTC
With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a
binary when the .mod files are generated, which means they don't yet
contain references to certain symbols that will be present in the final
binaries. This includes intrinsic functions, such as memcpy, memmove,
and memset [1], and stack protector symbols [2]. This change adds a
default symbol list to use with CONFIG_TRIM_UNUSED_KSYMS when Clang's
LTO is used.

[1] https://llvm.org/docs/LangRef.html#standard-c-c-library-intrinsics
[2] https://llvm.org/docs/LangRef.html#llvm-stackprotector-intrinsic

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 init/Kconfig                | 1 +
 scripts/lto-used-symbollist | 5 +++++
 2 files changed, 6 insertions(+)
 create mode 100644 scripts/lto-used-symbollist

Comments

Kees Cook Dec. 11, 2020, 7:32 p.m. UTC | #1
On Fri, Dec 11, 2020 at 10:46:23AM -0800, Sami Tolvanen wrote:
> With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a
> binary when the .mod files are generated, which means they don't yet
> contain references to certain symbols that will be present in the final
> binaries. This includes intrinsic functions, such as memcpy, memmove,
> and memset [1], and stack protector symbols [2]. This change adds a
> default symbol list to use with CONFIG_TRIM_UNUSED_KSYMS when Clang's
> LTO is used.
> 
> [1] https://llvm.org/docs/LangRef.html#standard-c-c-library-intrinsics
> [2] https://llvm.org/docs/LangRef.html#llvm-stackprotector-intrinsic
> 
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

> ---
>  init/Kconfig                | 1 +
>  scripts/lto-used-symbollist | 5 +++++
>  2 files changed, 6 insertions(+)
>  create mode 100644 scripts/lto-used-symbollist
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index 0872a5a2e759..e88c919c1bf1 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -2297,6 +2297,7 @@ config TRIM_UNUSED_KSYMS
>  config UNUSED_KSYMS_WHITELIST
>  	string "Whitelist of symbols to keep in ksymtab"
>  	depends on TRIM_UNUSED_KSYMS
> +	default "scripts/lto-used-symbollist" if LTO_CLANG
>  	help
>  	  By default, all unused exported symbols will be un-exported from the
>  	  build when TRIM_UNUSED_KSYMS is selected.
> diff --git a/scripts/lto-used-symbollist b/scripts/lto-used-symbollist
> new file mode 100644
> index 000000000000..38e7bb9ebaae
> --- /dev/null
> +++ b/scripts/lto-used-symbollist
> @@ -0,0 +1,5 @@
> +memcpy
> +memmove
> +memset
> +__stack_chk_fail
> +__stack_chk_guard
> -- 
> 2.29.2.576.ga3fc446d84-goog
> 

bikeshed: Should this filename use some kind of extension, like
lto-user-symbols.txt or .list, to make it more human-friendly?
Sami Tolvanen Dec. 11, 2020, 7:40 p.m. UTC | #2
On Fri, Dec 11, 2020 at 11:32 AM Kees Cook <keescook@chromium.org> wrote:
>
> On Fri, Dec 11, 2020 at 10:46:23AM -0800, Sami Tolvanen wrote:
> > With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a
> > binary when the .mod files are generated, which means they don't yet
> > contain references to certain symbols that will be present in the final
> > binaries. This includes intrinsic functions, such as memcpy, memmove,
> > and memset [1], and stack protector symbols [2]. This change adds a
> > default symbol list to use with CONFIG_TRIM_UNUSED_KSYMS when Clang's
> > LTO is used.
> >
> > [1] https://llvm.org/docs/LangRef.html#standard-c-c-library-intrinsics
> > [2] https://llvm.org/docs/LangRef.html#llvm-stackprotector-intrinsic
> >
> > Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> > ---
> >  init/Kconfig                | 1 +
> >  scripts/lto-used-symbollist | 5 +++++
> >  2 files changed, 6 insertions(+)
> >  create mode 100644 scripts/lto-used-symbollist
> >
> > diff --git a/init/Kconfig b/init/Kconfig
> > index 0872a5a2e759..e88c919c1bf1 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -2297,6 +2297,7 @@ config TRIM_UNUSED_KSYMS
> >  config UNUSED_KSYMS_WHITELIST
> >       string "Whitelist of symbols to keep in ksymtab"
> >       depends on TRIM_UNUSED_KSYMS
> > +     default "scripts/lto-used-symbollist" if LTO_CLANG
> >       help
> >         By default, all unused exported symbols will be un-exported from the
> >         build when TRIM_UNUSED_KSYMS is selected.
> > diff --git a/scripts/lto-used-symbollist b/scripts/lto-used-symbollist
> > new file mode 100644
> > index 000000000000..38e7bb9ebaae
> > --- /dev/null
> > +++ b/scripts/lto-used-symbollist
> > @@ -0,0 +1,5 @@
> > +memcpy
> > +memmove
> > +memset
> > +__stack_chk_fail
> > +__stack_chk_guard
> > --
> > 2.29.2.576.ga3fc446d84-goog
> >
>
> bikeshed: Should this filename use some kind of extension, like
> lto-user-symbols.txt or .list, to make it more human-friendly?

Sure, I can rename this in the next version. Does anyone have strong
opinions about the name and/or extension?

Sami
Nick Desaulniers Dec. 11, 2020, 7:45 p.m. UTC | #3
On Fri, Dec 11, 2020 at 11:40 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> On Fri, Dec 11, 2020 at 11:32 AM Kees Cook <keescook@chromium.org> wrote:
> >
> > On Fri, Dec 11, 2020 at 10:46:23AM -0800, Sami Tolvanen wrote:
> > > --- /dev/null
> > > +++ b/scripts/lto-used-symbollist
> > > @@ -0,0 +1,5 @@
> > > +memcpy
> > > +memmove
> > > +memset
> > > +__stack_chk_fail
> > > +__stack_chk_guard
> > > --
> > > 2.29.2.576.ga3fc446d84-goog
> > >
> >
> > bikeshed: Should this filename use some kind of extension, like
> > lto-user-symbols.txt or .list, to make it more human-friendly?
>
> Sure, I can rename this in the next version. Does anyone have strong
> opinions about the name and/or extension?

.txt extension would be fine.
diff mbox series

Patch

diff --git a/init/Kconfig b/init/Kconfig
index 0872a5a2e759..e88c919c1bf1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2297,6 +2297,7 @@  config TRIM_UNUSED_KSYMS
 config UNUSED_KSYMS_WHITELIST
 	string "Whitelist of symbols to keep in ksymtab"
 	depends on TRIM_UNUSED_KSYMS
+	default "scripts/lto-used-symbollist" if LTO_CLANG
 	help
 	  By default, all unused exported symbols will be un-exported from the
 	  build when TRIM_UNUSED_KSYMS is selected.
diff --git a/scripts/lto-used-symbollist b/scripts/lto-used-symbollist
new file mode 100644
index 000000000000..38e7bb9ebaae
--- /dev/null
+++ b/scripts/lto-used-symbollist
@@ -0,0 +1,5 @@ 
+memcpy
+memmove
+memset
+__stack_chk_fail
+__stack_chk_guard