mirror of
https://github.com/torvalds/linux.git
synced 2024-12-27 05:11:48 +00:00
3f086189cd
The BFD linker generates run-time relocations for z_input_len and z_output_len, even though they are absolute symbols. This is fixed for binutils-2.35 [1]. Work around this for earlier versions by defining two variables input_len and output_len in addition to the symbols, and use them via position-independent references. This eliminates the last two run-time relocations in the head code and allows us to drop the -z noreloc-overflow flag to the linker. Move the -pie and --no-dynamic-linker LDFLAGS to LDFLAGS_vmlinux instead of KBUILD_LDFLAGS. There shouldn't be anything else getting linked, but this is the more logical location for these flags, and modversions might call the linker if an EXPORT_SYMBOL is left over accidentally in one of the decompressors. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=25754 Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Fangrui Song <maskray@google.com> Link: https://lore.kernel.org/r/20200731230820.1742553-7-keescook@chromium.org
75 lines
1.6 KiB
C
75 lines
1.6 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* ----------------------------------------------------------------------- *
|
|
*
|
|
* Copyright (C) 2009 Intel Corporation. All rights reserved.
|
|
*
|
|
* H. Peter Anvin <hpa@linux.intel.com>
|
|
*
|
|
* -----------------------------------------------------------------------
|
|
*
|
|
* Outputs a small assembly wrapper with the appropriate symbols defined.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <inttypes.h>
|
|
#include <tools/le_byteshift.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
uint32_t olen;
|
|
long ilen;
|
|
FILE *f = NULL;
|
|
int retval = 1;
|
|
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
|
|
goto bail;
|
|
}
|
|
|
|
/* Get the information for the compressed kernel image first */
|
|
|
|
f = fopen(argv[1], "r");
|
|
if (!f) {
|
|
perror(argv[1]);
|
|
goto bail;
|
|
}
|
|
|
|
|
|
if (fseek(f, -4L, SEEK_END)) {
|
|
perror(argv[1]);
|
|
}
|
|
|
|
if (fread(&olen, sizeof(olen), 1, f) != 1) {
|
|
perror(argv[1]);
|
|
goto bail;
|
|
}
|
|
|
|
ilen = ftell(f);
|
|
olen = get_unaligned_le32(&olen);
|
|
|
|
printf(".section \".rodata..compressed\",\"a\",@progbits\n");
|
|
printf(".globl z_input_len\n");
|
|
printf("z_input_len = %lu\n", ilen);
|
|
printf(".globl z_output_len\n");
|
|
printf("z_output_len = %lu\n", (unsigned long)olen);
|
|
|
|
printf(".globl input_data, input_data_end\n");
|
|
printf("input_data:\n");
|
|
printf(".incbin \"%s\"\n", argv[1]);
|
|
printf("input_data_end:\n");
|
|
|
|
printf(".section \".rodata\",\"a\",@progbits\n");
|
|
printf(".globl input_len\n");
|
|
printf("input_len:\n\t.long %lu\n", ilen);
|
|
printf(".globl output_len\n");
|
|
printf("output_len:\n\t.long %lu\n", (unsigned long)olen);
|
|
|
|
retval = 0;
|
|
bail:
|
|
if (f)
|
|
fclose(f);
|
|
return retval;
|
|
}
|