1. 29 Nov, 2016 2 commits
    • Nicholas Piggin's avatar
      kbuild: minor improvement for thin archives build · abac4c89
      Nicholas Piggin authored
      The root built-in.o archive is currently generated before all object
      files are built for the final link, due to final build of init/ after
      version update. In practice it seems like it doesn't matter because
      the archive symbol table does not change, but it is more logical to
      create the final archive as the last step.
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
    • Nicholas Piggin's avatar
      kbuild: kallsyms allow 3-pass generation if symbols size has changed · 7e2b37c9
      Nicholas Piggin authored
      kallsyms generation is not foolproof, due to some linkers adding
      symbols (e.g., branch trampolines) when a binary size changes.
      Have it attempt a 3rd pass automatically if the kallsyms size changes
      in the 2nd pass.
      This allows powerpc64 allyesconfig to build without adding another
      pass when it's not required.
      This can be solved other ways by directing the linker not to add labels
      on branch stubs, or to move kallsyms near the end of the image. The
      former is undesirable for debugging/tracing, and the latter is a more
      significant change that requires more testing and review.
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
  2. 09 Sep, 2016 1 commit
    • Stephen Rothwell's avatar
      kbuild: allow architectures to use thin archives instead of ld -r · a5967db9
      Stephen Rothwell authored
      ld -r is an incremental link used to create built-in.o files in build
      subdirectories. It produces relocatable object files containing all
      its input files, and these are are then pulled together and relocated
      in the final link. Aside from the bloat, this constrains the final
      link relocations, which has bitten large powerpc builds with
      unresolvable relocations in the final link.
      Alan Modra has recommended the kernel use thin archives for linking.
      This is an alternative and means that the linker has more information
      available to it when it links the kernel.
      This patch enables a config option architectures can select, which
      causes all built-in.o files to be built as thin archives. built-in.o
      files in subdirectories do not get symbol table or index attached,
      which improves speed and size. The final link pass creates a
      built-in.o archive in the root output directory which includes the
      symbol table and index. The linker then uses takes this file to link.
      The --whole-archive linker option is required, because the linker now
      has visibility to every individual object file, and it will otherwise
      just completely avoid including those without external references
      (consider a file with EXPORT_SYMBOL or initcall or hardware exceptions
      as its only entry points). The traditional built works "by luck" as
      built-in.o files are large enough that they're going to get external
      references. However this optimisation is unpredictable for the kernel
      (due to above external references), ineffective at culling unused, and
      costly because the .o files have to be searched for references.
      Superior alternatives for link-time culling should be used instead.
      Build characteristics for inclink vs thinarc, on a small powerpc64le
      pseries VM with a modest .config:
                                        inclink       thinarc
      vmlinux                        15 618 680    15 625 028
      sum of all built-in.o          56 091 808     1 054 334
      sum excluding root built-in.o                   151 430
      find -name built-in.o | xargs rm ; time make vmlinux
      real                              22.772s       21.143s
      user                              13.280s       13.430s
      sys                                4.310s        2.750s
      - Final kernel pulled in only about 6K more, which shows how
        ineffective the object file culling is.
      - Build performance looks improved due to less pagecache activity.
        On IO constrained systems it could be a bigger win.
      - Build size saving is significant.
      Side note, the toochain understands archives, so there's some tricks,
      $ ar t built-in.o          # list all files you linked with
      $ size built-in.o          # and their sizes
      $ objdump -d built-in.o    # disassembly (unrelocated) with filenames
      Implementation by sfr, minor tweaks by npiggin.
      Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
  3. 07 Jun, 2016 1 commit
    • Emese Revfy's avatar
      GCC plugin infrastructure · 6b90bd4b
      Emese Revfy authored
      This patch allows to build the whole kernel with GCC plugins. It was ported from
      grsecurity/PaX. The infrastructure supports building out-of-tree modules and
      building in a separate directory. Cross-compilation is supported too.
      Currently the x86, arm, arm64 and uml architectures enable plugins.
      The directory of the gcc plugins is scripts/gcc-plugins. You can use a file or a directory
      there. The plugins compile with these options:
       * -fno-rtti: gcc is compiled with this option so the plugins must use it too
       * -fno-exceptions: this is inherited from gcc too
       * -fasynchronous-unwind-tables: this is inherited from gcc too
       * -ggdb: it is useful for debugging a plugin (better backtrace on internal
       * -Wno-narrowing: to suppress warnings from gcc headers (ipa-utils.h)
       * -Wno-unused-variable: to suppress warnings from gcc headers (gcc_version
          variable, plugin-version.h)
      The infrastructure introduces a new Makefile target called gcc-plugins. It
      supports all gcc versions from 4.5 to 6.0. The scripts/gcc-plugin.sh script
      chooses the proper host compiler (gcc-4.7 can be built by either gcc or g++).
      This script also checks the availability of the included headers in
      The gcc-common.h header contains frequently included headers for GCC plugins
      and it has a compatibility layer for the supported gcc versions.
      The gcc-generate-*-pass.h headers automatically generate the registration
      structures for GIMPLE, SIMPLE_IPA, IPA and RTL passes.
      Note that 'make clean' keeps the *.so files (only the distclean or mrproper
      targets clean all) because they are needed for out-of-tree modules.
      Based on work created by the PaX Team.
      Signed-off-by: default avatarEmese Revfy <re.emese@gmail.com>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.com>
  4. 07 Apr, 2016 1 commit
  5. 15 Mar, 2016 2 commits
    • Ard Biesheuvel's avatar
      kallsyms: add support for relative offsets in kallsyms address table · 2213e9a6
      Ard Biesheuvel authored
      Similar to how relative extables are implemented, it is possible to emit
      the kallsyms table in such a way that it contains offsets relative to
      some anchor point in the kernel image rather than absolute addresses.
      On 64-bit architectures, it cuts the size of the kallsyms address table
      in half, since offsets between kernel symbols can typically be expressed
      in 32 bits.  This saves several hundreds of kilobytes of permanent
      .rodata on average.  In addition, the kallsyms address table is no
      longer subject to dynamic relocation when CONFIG_RELOCATABLE is in
      effect, so the relocation work done after decompression now doesn't have
      to do relocation updates for all these values.  This saves up to 24
      bytes (i.e., the size of a ELF64 RELA relocation table entry) per value,
      which easily adds up to a couple of megabytes of uncompressed __init
      data on ppc64 or arm64.  Even if these relocation entries typically
      compress well, the combined size reduction of 2.8 MB uncompressed for a
      ppc64_defconfig build (of which 2.4 MB is __init data) results in a ~500
      KB space saving in the compressed image.
      Since it is useful for some architectures (like x86) to retain the
      ability to emit absolute values as well, this patch also adds support
      for capturing both absolute and relative values when
      KALLSYMS_ABSOLUTE_PERCPU is in effect, by emitting absolute per-cpu
      addresses as positive 32-bit values, and addresses relative to the
      lowest encountered relative symbol as negative values, which are
      subtracted from the runtime address of this base symbol to produce the
      actual address.
      Support for the above is enabled by default for all architectures except
      IA-64 and Tile-GX, whose symbols are too far apart to capture in this
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Tested-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Michal Marek <mmarek@suse.cz>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Ard Biesheuvel's avatar
      x86: kallsyms: disable absolute percpu symbols on !SMP · 4d5d5664
      Ard Biesheuvel authored
      scripts/kallsyms.c has a special --absolute-percpu command line option
      which deals with the zero based per cpu offsets that are used when
      building for SMP on x86_64.  This means that the option should only be
      passed in that case, so add a Kconfig symbol with the correct predicate,
      and use that instead.
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
      Tested-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Tested-by: default avatarKees Cook <keescook@chromium.org>
      Acked-by: default avatarRusty Russell <rusty@rustcorp.com.au>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Michal Marek <mmarek@suse.cz>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  6. 08 Feb, 2016 1 commit
  7. 10 Jan, 2016 1 commit
    • Vegard Nossum's avatar
      um: link with -lpthread · a7df4716
      Vegard Nossum authored
      Similarly to commit fb1770aa, with gcc 5
      on Ubuntu and CONFIG_STATIC_LINK=y I was seeing these linker errors:
      /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new':
      (.text+0xcd): undefined reference to `pthread_once'
      /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new':
      (.text+0x126): undefined reference to `pthread_attr_init'
      /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new':
      (.text+0x168): undefined reference to `pthread_attr_setdetachstate'
      Obviously we also need -lpthread for librt.a.
      Cc: stable@vger.kernel.org # 4.4
      Signed-off-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
  8. 08 Dec, 2015 1 commit
    • Lorenzo Colitti's avatar
      arch: um: fix error when linking vmlinux. · fb1770aa
      Lorenzo Colitti authored
      On gcc Ubuntu 4.8.4-2ubuntu1~14.04, linking vmlinux fails with:
      arch/um/os-Linux/built-in.o: In function `os_timer_create':
      /android/kernel/android/arch/um/os-Linux/time.c:51: undefined reference to `timer_create'
      arch/um/os-Linux/built-in.o: In function `os_timer_set_interval':
      /android/kernel/android/arch/um/os-Linux/time.c:84: undefined reference to `timer_settime'
      arch/um/os-Linux/built-in.o: In function `os_timer_remain':
      /android/kernel/android/arch/um/os-Linux/time.c:109: undefined reference to `timer_gettime'
      arch/um/os-Linux/built-in.o: In function `os_timer_one_shot':
      /android/kernel/android/arch/um/os-Linux/time.c:132: undefined reference to `timer_settime'
      arch/um/os-Linux/built-in.o: In function `os_timer_disable':
      /android/kernel/android/arch/um/os-Linux/time.c:145: undefined reference to `timer_settime'
      This is because -lrt appears in the generated link commandline
      after arch/um/os-Linux/built-in.o. Fix this by removing -lrt from
      arch/um/Makefile and adding it to the UM-specific section of
      Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
      Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
  9. 21 May, 2015 1 commit
  10. 07 May, 2015 1 commit
  11. 20 Aug, 2014 1 commit
  12. 17 Mar, 2014 1 commit
    • Rusty Russell's avatar
      kallsyms: fix percpu vars on x86-64 with relocation. · c6bda7c9
      Rusty Russell authored
      x86-64 has a problem: per-cpu variables are actually represented by
      their absolute offsets within the per-cpu area, but the symbols are
      not emitted as absolute.  Thus kallsyms naively creates them as offsets
      from _text, meaning their values change if the kernel is relocated
      (especially noticeable with CONFIG_RANDOMIZE_BASE):
       $ egrep ' (gdt_|_(stext|_per_cpu_))' /root/kallsyms.nokaslr
       0000000000000000 D __per_cpu_start
       0000000000004000 D gdt_page
       0000000000014280 D __per_cpu_end
       ffffffff810001c8 T _stext
       ffffffff81ee53c0 D __per_cpu_offset
       $ egrep ' (gdt_|_(stext|_per_cpu_))' /root/kallsyms.kaslr1
       000000001f200000 D __per_cpu_start
       000000001f204000 D gdt_page
       000000001f214280 D __per_cpu_end
       ffffffffa02001c8 T _stext
       ffffffffa10e53c0 D __per_cpu_offset
      Making them absolute symbols is the Right Thing, but requires fixes to
      the relocs tool.  So for the moment, we add a --absolute-percpu option
      which makes them absolute from a kallsyms perspective:
       $ egrep ' (gdt_|_(stext|_per_cpu_))' /proc/kallsyms # no KASLR
       0000000000000000 A __per_cpu_start
       000000000000a000 A gdt_page
       0000000000013040 A __per_cpu_end
       ffffffff802001c8 T _stext
       ffffffff8099b180 D __per_cpu_offset
       ffffffff809a3000 D __per_cpu_load
       $ egrep ' (gdt_|_(stext|_per_cpu_))' /proc/kallsyms # With KASLR
       0000000000000000 A __per_cpu_start
       000000000000a000 A gdt_page
       0000000000013040 A __per_cpu_end
       ffffffff89c001c8 T _stext
       ffffffff8a39d180 D __per_cpu_offset
       ffffffff8a3a5000 D __per_cpu_load
      Based-on-the-original-screenplay-by: default avatarAndy Honig <ahonig@google.com>
      Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
  13. 10 Dec, 2013 1 commit
  14. 01 Nov, 2013 1 commit
    • Ming Lei's avatar
      scripts/kallsyms: filter symbols not in kernel address space · f6537f2f
      Ming Lei authored
      This patch uses CONFIG_PAGE_OFFSET to filter symbols which
      are not in kernel address space because these symbols are
      generally for generating code purpose and can't be run at
      kernel mode, so we needn't keep them in /proc/kallsyms.
      For example, on ARM there are some symbols which may be
      linked in relocatable code section, then perf can't parse
      symbols any more from /proc/kallsyms, this patch fixes the
      problem (introduced b9b32bf7)
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: Michal Marek <mmarek@suse.cz>
      Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
      Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
      Cc: stable@vger.kernel.org
  15. 15 Mar, 2013 1 commit
    • Rusty Russell's avatar
      CONFIG_SYMBOL_PREFIX: cleanup. · b92021b0
      Rusty Russell authored
      We have CONFIG_SYMBOL_PREFIX, which three archs define to the string
      "_".  But Al Viro broke this in "consolidate cond_syscall and
      SYSCALL_ALIAS declarations" (in linux-next), and he's not the first to
      do so.
      Using CONFIG_SYMBOL_PREFIX is awkward, since we usually just want to
      prefix it so something.  So various places define helpers which are
      defined to nothing if CONFIG_SYMBOL_PREFIX isn't set:
      1) include/asm-generic/unistd.h defines __SYMBOL_PREFIX.
      2) include/asm-generic/vmlinux.lds.h defines VMLINUX_SYMBOL(sym)
      3) include/linux/export.h defines MODULE_SYMBOL_PREFIX.
      4) include/linux/kernel.h defines SYMBOL_PREFIX (which differs from #7)
      5) kernel/modsign_certificate.S defines ASM_SYMBOL(sym)
      6) scripts/modpost.c defines MODULE_SYMBOL_PREFIX
      7) scripts/Makefile.lib defines SYMBOL_PREFIX on the commandline if
         CONFIG_SYMBOL_PREFIX is set, so that we have a non-string version
         for pasting.
      (arch/h8300/include/asm/linkage.h defines SYMBOL_NAME(), too).
      Let's solve this properly:
      1) No more generic prefix, just CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX.
      2) Make linux/export.h usable from asm.
      4) Make everyone use them.
      Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
      Reviewed-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Tested-by: James Hogan <james.hogan@imgtec.com> (metag)
  16. 25 Feb, 2013 1 commit
  17. 22 Feb, 2013 1 commit
  18. 11 Sep, 2012 1 commit
    • James Hogan's avatar
      kbuild: add symbol prefix arg to kallsyms · 6895f97e
      James Hogan authored
      Commit 1f2bfbd0 ("kbuild: link of
      vmlinux moved to a script") introduced in v3.5-rc1 broke kallsyms on
      architectures which have symbol prefixes.
      The --symbol-prefix argument used to be added to the KALLSYMS command
      line from the architecture Makefile, however this isn't picked up by the
      new scripts/link-vmlinux.sh. This resulted in symbols like
      kallsyms_addresses being added which weren't correctly overriding the
      weak symbols such as _kallsyms_addresses. These could then trigger
      BUG_ONs in kallsyms code.
      This is fixed by removing the KALLSYMS addition from the architecture
      Makefile, and using CONFIG_SYMBOL_PREFIX in the link-vmlinux.sh script
      to determine whether to add the --symbol-prefix argument.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Signed-off-by: default avatarBob Liu <lliubbo@gmail.com>
  19. 10 Aug, 2012 1 commit
  20. 07 Jul, 2012 1 commit
  21. 10 May, 2012 1 commit
  22. 05 May, 2012 1 commit
    • Sam Ravnborg's avatar
      kbuild: link of vmlinux moved to a script · 1f2bfbd0
      Sam Ravnborg authored
      Move the final link of vmlinux to a script to improve
      readability and maintainability of the code.
      The Makefile fragments used to link vmlinux has over the
      years seen far too many changes and the logic had become
      hard to follow.
      As the process by nature is serialized there was
      nothing gained including this in the Makefile.
      "um" has special link requirments - and the
      only way to handle this was to hard-code the linking
      of "um" in the script.
      This was better than trying to modularize it only for the
      benefit of "um" anyway.
      The shell script has been improved after input from:
      Arnaud Lacombe <lacombar@gmail.com>
      Nick Bowler <nbowler@elliptictech.com>
      Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
      Cc: Arnaud Lacombe <lacombar@gmail.com>
      Cc: Nick Bowler <nbowler@elliptictech.com>
      Cc: Richard Weinberger <richard@nod.at>
      Signed-off-by: default avatarMichal Marek <mmarek@suse.cz>