License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2007-07-21 22:10:01 +07:00
|
|
|
#
|
2008-01-30 19:30:42 +07:00
|
|
|
# Building vDSO images for x86.
|
2007-07-21 22:10:01 +07:00
|
|
|
#
|
|
|
|
|
2014-02-08 15:01:05 +07:00
|
|
|
KBUILD_CFLAGS += $(DISABLE_LTO)
|
2016-02-29 11:22:34 +07:00
|
|
|
KASAN_SANITIZE := n
|
|
|
|
UBSAN_SANITIZE := n
|
|
|
|
OBJECT_FILES_NON_STANDARD := y
|
2014-02-08 15:01:05 +07:00
|
|
|
|
kernel: add kcov code coverage
kcov provides code coverage collection for coverage-guided fuzzing
(randomized testing). Coverage-guided fuzzing is a testing technique
that uses coverage feedback to determine new interesting inputs to a
system. A notable user-space example is AFL
(http://lcamtuf.coredump.cx/afl/). However, this technique is not
widely used for kernel testing due to missing compiler and kernel
support.
kcov does not aim to collect as much coverage as possible. It aims to
collect more or less stable coverage that is function of syscall inputs.
To achieve this goal it does not collect coverage in soft/hard
interrupts and instrumentation of some inherently non-deterministic or
non-interesting parts of kernel is disbled (e.g. scheduler, locking).
Currently there is a single coverage collection mode (tracing), but the
API anticipates additional collection modes. Initially I also
implemented a second mode which exposes coverage in a fixed-size hash
table of counters (what Quentin used in his original patch). I've
dropped the second mode for simplicity.
This patch adds the necessary support on kernel side. The complimentary
compiler support was added in gcc revision 231296.
We've used this support to build syzkaller system call fuzzer, which has
found 90 kernel bugs in just 2 months:
https://github.com/google/syzkaller/wiki/Found-Bugs
We've also found 30+ bugs in our internal systems with syzkaller.
Another (yet unexplored) direction where kcov coverage would greatly
help is more traditional "blob mutation". For example, mounting a
random blob as a filesystem, or receiving a random blob over wire.
Why not gcov. Typical fuzzing loop looks as follows: (1) reset
coverage, (2) execute a bit of code, (3) collect coverage, repeat. A
typical coverage can be just a dozen of basic blocks (e.g. an invalid
input). In such context gcov becomes prohibitively expensive as
reset/collect coverage steps depend on total number of basic
blocks/edges in program (in case of kernel it is about 2M). Cost of
kcov depends only on number of executed basic blocks/edges. On top of
that, kernel requires per-thread coverage because there are always
background threads and unrelated processes that also produce coverage.
With inlined gcov instrumentation per-thread coverage is not possible.
kcov exposes kernel PCs and control flow to user-space which is
insecure. But debugfs should not be mapped as user accessible.
Based on a patch by Quentin Casasnovas.
[akpm@linux-foundation.org: make task_struct.kcov_mode have type `enum kcov_mode']
[akpm@linux-foundation.org: unbreak allmodconfig]
[akpm@linux-foundation.org: follow x86 Makefile layout standards]
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: syzkaller <syzkaller@googlegroups.com>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Tavis Ormandy <taviso@google.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Kees Cook <keescook@google.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: David Drysdale <drysdale@google.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-03-23 04:27:30 +07:00
|
|
|
# Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
|
|
|
|
KCOV_INSTRUMENT := n
|
|
|
|
|
2008-01-30 19:30:42 +07:00
|
|
|
VDSO64-$(CONFIG_X86_64) := y
|
2012-02-20 02:38:06 +07:00
|
|
|
VDSOX32-$(CONFIG_X86_X32_ABI) := y
|
2008-01-30 19:30:42 +07:00
|
|
|
VDSO32-$(CONFIG_X86_32) := y
|
2015-06-22 18:55:15 +07:00
|
|
|
VDSO32-$(CONFIG_IA32_EMULATION) := y
|
2008-01-30 19:30:42 +07:00
|
|
|
|
2007-07-21 22:10:01 +07:00
|
|
|
# files to link into the vdso
|
2014-07-11 08:13:16 +07:00
|
|
|
vobjs-y := vdso-note.o vclock_gettime.o vgetcpu.o
|
2012-02-20 02:38:06 +07:00
|
|
|
|
2007-07-21 22:10:01 +07:00
|
|
|
# files to link into kernel
|
2014-03-18 05:22:08 +07:00
|
|
|
obj-y += vma.o
|
2016-02-29 11:22:34 +07:00
|
|
|
OBJECT_FILES_NON_STANDARD_vma.o := n
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
|
|
|
|
# vDSO images to build
|
|
|
|
vdso_img-$(VDSO64-y) += 64
|
|
|
|
vdso_img-$(VDSOX32-y) += x32
|
2015-10-06 07:47:56 +07:00
|
|
|
vdso_img-$(VDSO32-y) += 32
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
|
|
|
|
obj-$(VDSO32-y) += vdso32-setup.o
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2014-06-13 07:53:12 +07:00
|
|
|
vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
|
2007-07-21 22:10:01 +07:00
|
|
|
|
|
|
|
$(obj)/vdso.o: $(obj)/vdso.so
|
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
targets += vdso.lds $(vobjs-y)
|
|
|
|
|
|
|
|
# Build the vDSO image C files and link them in.
|
|
|
|
vdso_img_objs := $(vdso_img-y:%=vdso-image-%.o)
|
|
|
|
vdso_img_cfiles := $(vdso_img-y:%=vdso-image-%.c)
|
|
|
|
vdso_img_sodbg := $(vdso_img-y:%=vdso%.so.dbg)
|
|
|
|
obj-y += $(vdso_img_objs)
|
|
|
|
targets += $(vdso_img_cfiles)
|
kbuild: mark $(targets) as .SECONDARY and remove .PRECIOUS markers
GNU Make automatically deletes intermediate files that are updated
in a chain of pattern rules.
Example 1) %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
Example 2) %.o <- %.c <- %.c_shipped
A couple of makefiles mark such targets as .PRECIOUS to prevent Make
from deleting them, but the correct way is to use .SECONDARY.
.SECONDARY
Prerequisites of this special target are treated as intermediate
files but are never automatically deleted.
.PRECIOUS
When make is interrupted during execution, it may delete the target
file it is updating if the file was modified since make started.
If you mark the file as precious, make will never delete the file
if interrupted.
Both can avoid deletion of intermediate files, but the difference is
the behavior when Make is interrupted; .SECONDARY deletes the target,
but .PRECIOUS does not.
The use of .PRECIOUS is relatively rare since we do not want to keep
partially constructed (possibly corrupted) targets.
Another difference is that .PRECIOUS works with pattern rules whereas
.SECONDARY does not.
.PRECIOUS: $(obj)/%.lex.c
works, but
.SECONDARY: $(obj)/%.lex.c
has no effect. However, for the reason above, I do not want to use
.PRECIOUS which could cause obscure build breakage.
The targets specified as .SECONDARY must be explicit. $(targets)
contains all targets that need to include .*.cmd files. So, the
intermediates you want to keep are mostly in there. Therefore, mark
$(targets) as .SECONDARY. It means primary targets are also marked
as .SECONDARY, but I do not see any drawback for this.
I replaced some .SECONDARY / .PRECIOUS markers with 'targets'. This
will make Kbuild search for non-existing .*.cmd files, but this is
not a noticeable performance issue.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Frank Rowand <frowand.list@gmail.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
2018-03-23 20:04:39 +07:00
|
|
|
targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2018-05-15 09:52:23 +07:00
|
|
|
CPPFLAGS_vdso.lds += -P -C
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2018-08-04 00:39:31 +07:00
|
|
|
VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
|
2018-12-07 02:12:31 +07:00
|
|
|
-z max-page-size=4096
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2018-05-15 09:52:24 +07:00
|
|
|
$(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
|
2008-01-30 19:30:44 +07:00
|
|
|
$(call if_changed,vdso)
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2016-07-23 11:35:40 +07:00
|
|
|
HOST_EXTRACFLAGS += -I$(srctree)/tools/include -I$(srctree)/include/uapi -I$(srctree)/arch/$(SUBARCH)/include/uapi
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
hostprogs-y += vdso2c
|
|
|
|
|
|
|
|
quiet_cmd_vdso2c = VDSO2C $@
|
2018-07-03 08:50:14 +07:00
|
|
|
cmd_vdso2c = $(obj)/vdso2c $< $(<:%.dbg=%) $@
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
|
2014-07-11 08:13:16 +07:00
|
|
|
$(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
$(call if_changed,vdso2c)
|
2007-10-17 23:04:32 +07:00
|
|
|
|
2011-05-23 20:31:29 +07:00
|
|
|
#
|
|
|
|
# Don't omit frame pointers for ease of userspace debugging, but do
|
|
|
|
# optimize sibling calls.
|
|
|
|
#
|
2008-04-15 02:19:30 +07:00
|
|
|
CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
|
2011-05-23 20:31:29 +07:00
|
|
|
$(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
|
2014-06-25 03:46:52 +07:00
|
|
|
-fno-omit-frame-pointer -foptimize-sibling-calls \
|
2018-10-03 11:26:50 +07:00
|
|
|
-DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
|
|
|
|
|
|
|
|
ifdef CONFIG_RETPOLINE
|
|
|
|
ifneq ($(RETPOLINE_VDSO_CFLAGS),)
|
|
|
|
CFL += $(RETPOLINE_VDSO_CFLAGS)
|
|
|
|
endif
|
|
|
|
endif
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2018-08-17 02:41:15 +07:00
|
|
|
$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
|
2007-07-21 22:10:01 +07:00
|
|
|
|
2011-05-23 20:31:29 +07:00
|
|
|
#
|
|
|
|
# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
|
|
|
|
#
|
|
|
|
CFLAGS_REMOVE_vdso-note.o = -pg
|
|
|
|
CFLAGS_REMOVE_vclock_gettime.o = -pg
|
|
|
|
CFLAGS_REMOVE_vgetcpu.o = -pg
|
|
|
|
CFLAGS_REMOVE_vvar.o = -pg
|
|
|
|
|
2012-02-20 02:38:06 +07:00
|
|
|
#
|
|
|
|
# X32 processes use x32 vDSO to access 64bit kernel data.
|
|
|
|
#
|
|
|
|
# Build x32 vDSO image:
|
|
|
|
# 1. Compile x32 vDSO as 64bit.
|
|
|
|
# 2. Convert object files to x32.
|
|
|
|
# 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
|
|
|
|
# so that it can reach 64bit address space with 64bit pointers.
|
|
|
|
#
|
|
|
|
|
|
|
|
CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
|
2018-08-04 00:39:31 +07:00
|
|
|
VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
|
2018-12-07 02:12:31 +07:00
|
|
|
-z max-page-size=4096
|
2012-02-20 02:38:06 +07:00
|
|
|
|
2014-06-13 07:53:12 +07:00
|
|
|
# x32-rebranded versions
|
2018-05-15 09:52:22 +07:00
|
|
|
vobjx32s-y := $(vobjs-y:.o=-x32.o)
|
2014-06-13 07:53:12 +07:00
|
|
|
|
|
|
|
# same thing, but in the output directory
|
2012-02-20 02:38:06 +07:00
|
|
|
vobjx32s := $(foreach F,$(vobjx32s-y),$(obj)/$F)
|
|
|
|
|
|
|
|
# Convert 64bit object file to x32 for x32 vDSO.
|
|
|
|
quiet_cmd_x32 = X32 $@
|
|
|
|
cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
|
|
|
|
|
|
|
|
$(obj)/%-x32.o: $(obj)/%.o FORCE
|
|
|
|
$(call if_changed,x32)
|
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 02:19:34 +07:00
|
|
|
targets += vdsox32.lds $(vobjx32s-y)
|
2012-02-20 02:38:06 +07:00
|
|
|
|
2014-07-11 08:13:16 +07:00
|
|
|
$(obj)/%.so: OBJCOPYFLAGS := -S
|
|
|
|
$(obj)/%.so: $(obj)/%.so.dbg
|
|
|
|
$(call if_changed,objcopy)
|
|
|
|
|
2018-05-15 09:52:24 +07:00
|
|
|
$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE
|
2012-02-20 02:38:06 +07:00
|
|
|
$(call if_changed,vdso)
|
|
|
|
|
2008-01-30 19:30:42 +07:00
|
|
|
CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
|
2018-08-04 00:39:31 +07:00
|
|
|
VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
|
2008-01-30 19:30:42 +07:00
|
|
|
|
|
|
|
targets += vdso32/vdso32.lds
|
2016-06-10 03:57:04 +07:00
|
|
|
targets += vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o
|
2014-07-11 08:13:16 +07:00
|
|
|
targets += vdso32/vclock_gettime.o
|
2008-01-30 19:30:42 +07:00
|
|
|
|
2015-10-06 07:47:58 +07:00
|
|
|
KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) -DBUILD_VDSO
|
2015-10-06 07:47:56 +07:00
|
|
|
$(obj)/vdso32.so.dbg: KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
|
|
|
|
$(obj)/vdso32.so.dbg: asflags-$(CONFIG_X86_64) += -m32
|
2008-01-30 19:30:42 +07:00
|
|
|
|
2014-03-18 05:22:09 +07:00
|
|
|
KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
|
|
|
|
KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
|
|
|
|
KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
|
|
|
|
KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
|
2016-05-24 05:09:38 +07:00
|
|
|
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
|
2018-08-17 02:41:15 +07:00
|
|
|
KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
|
2014-03-18 05:22:09 +07:00
|
|
|
KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
|
2014-03-18 05:22:12 +07:00
|
|
|
KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
|
|
|
|
KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
|
|
|
|
KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
|
2014-06-25 03:46:52 +07:00
|
|
|
KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
|
2018-10-03 11:26:50 +07:00
|
|
|
|
|
|
|
ifdef CONFIG_RETPOLINE
|
|
|
|
ifneq ($(RETPOLINE_VDSO_CFLAGS),)
|
|
|
|
KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2015-10-06 07:47:56 +07:00
|
|
|
$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
|
2014-03-18 05:22:09 +07:00
|
|
|
|
2015-10-06 07:47:56 +07:00
|
|
|
$(obj)/vdso32.so.dbg: FORCE \
|
|
|
|
$(obj)/vdso32/vdso32.lds \
|
|
|
|
$(obj)/vdso32/vclock_gettime.o \
|
|
|
|
$(obj)/vdso32/note.o \
|
2016-06-10 03:57:04 +07:00
|
|
|
$(obj)/vdso32/system_call.o \
|
|
|
|
$(obj)/vdso32/sigreturn.o
|
2008-01-30 19:30:42 +07:00
|
|
|
$(call if_changed,vdso)
|
|
|
|
|
|
|
|
#
|
|
|
|
# The DSO images are built using a special linker script.
|
|
|
|
#
|
|
|
|
quiet_cmd_vdso = VDSO $@
|
2018-08-04 00:39:31 +07:00
|
|
|
cmd_vdso = $(LD) -nostdlib -o $@ \
|
2008-01-30 19:30:42 +07:00
|
|
|
$(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
|
2018-08-04 00:39:31 +07:00
|
|
|
-T $(filter %.lds,$^) $(filter %.o,$^) && \
|
2010-06-19 04:36:26 +07:00
|
|
|
sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
|
2008-01-30 19:30:42 +07:00
|
|
|
|
2018-08-04 00:39:31 +07:00
|
|
|
VDSO_LDFLAGS = -shared $(call ld-option, --hash-style=both) \
|
2018-12-15 05:36:37 +07:00
|
|
|
$(call ld-option, --build-id) $(call ld-option, --eh-frame-hdr) \
|
|
|
|
-Bsymbolic
|
2009-06-18 06:28:09 +07:00
|
|
|
GCOV_PROFILE := n
|
2008-01-30 19:30:42 +07:00
|
|
|
|
|
|
|
#
|
2014-06-21 02:20:44 +07:00
|
|
|
# Install the unstripped copies of vdso*.so. If our toolchain supports
|
|
|
|
# build-id, install .build-id links as well.
|
2008-01-30 19:30:42 +07:00
|
|
|
#
|
2014-06-12 22:28:10 +07:00
|
|
|
quiet_cmd_vdso_install = INSTALL $(@:install_%=%)
|
2014-06-21 02:20:44 +07:00
|
|
|
define cmd_vdso_install
|
|
|
|
cp $< "$(MODLIB)/vdso/$(@:install_%=%)"; \
|
|
|
|
if readelf -n $< |grep -q 'Build ID'; then \
|
|
|
|
buildid=`readelf -n $< |grep 'Build ID' |sed -e 's/^.*Build ID: \(.*\)$$/\1/'`; \
|
|
|
|
first=`echo $$buildid | cut -b-2`; \
|
|
|
|
last=`echo $$buildid | cut -b3-`; \
|
|
|
|
mkdir -p "$(MODLIB)/vdso/.build-id/$$first"; \
|
|
|
|
ln -sf "../../$(@:install_%=%)" "$(MODLIB)/vdso/.build-id/$$first/$$last.debug"; \
|
|
|
|
fi
|
|
|
|
endef
|
2014-06-12 22:28:10 +07:00
|
|
|
|
|
|
|
vdso_img_insttargets := $(vdso_img_sodbg:%.dbg=install_%)
|
|
|
|
|
|
|
|
$(MODLIB)/vdso: FORCE
|
2007-10-17 23:04:32 +07:00
|
|
|
@mkdir -p $(MODLIB)/vdso
|
2014-06-12 22:28:10 +07:00
|
|
|
|
2016-03-13 07:13:55 +07:00
|
|
|
$(vdso_img_insttargets): install_%: $(obj)/%.dbg $(MODLIB)/vdso
|
2007-10-17 23:04:32 +07:00
|
|
|
$(call cmd,vdso_install)
|
|
|
|
|
2014-06-12 22:28:10 +07:00
|
|
|
PHONY += vdso_install $(vdso_img_insttargets)
|
2016-03-13 07:13:55 +07:00
|
|
|
vdso_install: $(vdso_img_insttargets)
|
2008-01-30 19:32:27 +07:00
|
|
|
|
2015-10-06 07:47:56 +07:00
|
|
|
clean-files := vdso32.so vdso32.so.dbg vdso64* vdso-image-*.c vdsox32.so*
|