Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp577907ybs; Sun, 24 May 2020 14:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEf6+hqDtqtrnOu6zCxvtjWhwsjH4ZiD1euP6MywHBANmrWSOdeKGoLOoGNcfIsptTVgHG X-Received: by 2002:a17:906:7a1c:: with SMTP id d28mr15983966ejo.10.1590355855510; Sun, 24 May 2020 14:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590355855; cv=none; d=google.com; s=arc-20160816; b=INtp36PCeoZUlrEv+TorNRpFU2NXfXiUkH1qmeWSxyC06PwRGUkmGqQJ3A+p87rTop RmE88yq+kuqS0OgT/2Cp0XQcLJUABZbse2o8BDmza9HKpPK6WDaI5A8peycf1JYL/UVv kpu/83P24rTt3FAkaEvHaRhKk2Dn4Fcsyc5s0tSpJXiPDqsGYVjj3poN2KqLQWJdrYED FEZdkxG3DgvQp9okfZ5htkNobs96HTMqF6YJX2UGwI1hrYbD0+ax3nDkz1ecl7siJhXC yaN5LPnRzGAVYhnpTjMoWBsANfUS9grcva0ESV1DpUFpPoBQ616hdKt4fy18diYu4BHx UmyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=AOa+r6gjXO8kd7k2MrQ1bCP3aAn9R5Cfdvk0rMFcdAo=; b=GveOVnKVC1CaLYYq3PADF4gAKQNO3tV0vSi+KSZxyY8A5WBJbCb5XEh1kTz0gR2OeA 4ClpH+ThONkNq9LKqS6ABEzNorAGCKesWmIy11QsWnU1nLy4s066LI3oy20c5+VJyoV1 Lb3069vVpatqYfV1Isam48RKCv10i49gyzjeMqfm0iBEMZXRQVjKQIGtNju5BOFc8sZf LO0MPh8MlcZl3b0aOya3zQYfg7Z82ohY6mObrg6qvKDhEomvgUgzLFF6e/JZyEGjUlbl 7LJRFGlT6a/ATUb+J7BHm0bWFa9aqfx1S38jH/2aUOqgVJzrflXK4lsem7m8myz+E+10 JBiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si8656492eja.345.2020.05.24.14.30.33; Sun, 24 May 2020 14:30:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388380AbgEXV2Z (ORCPT + 99 others); Sun, 24 May 2020 17:28:25 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44822 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388346AbgEXV2W (ORCPT ); Sun, 24 May 2020 17:28:22 -0400 Received: by mail-qt1-f193.google.com with SMTP id c12so2702121qtq.11 for ; Sun, 24 May 2020 14:28:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AOa+r6gjXO8kd7k2MrQ1bCP3aAn9R5Cfdvk0rMFcdAo=; b=pyd3qJveQexBcm4/DgPq0pnL1nuNFPIPDSy0yOgvXYLhy85p+ziESb6JT3/R9kghE0 zgNRuVWsWRdIyQHcTvGcegDGW7LtqlMayNVuNvPjEDooMlRO912cygNDrbYviAxAZtrI aS1Ka35mIyn7AweK7cJCnKAfO0NRgVIW5xmMrjZK42U6LevzX7xkyBSzRoUKRAoIGqxy 9xao2yTP1UuqIBwn9CAD7GWokCQkPI/5D+CMk7H++dp0f1iPJLr35fGHZ2IaNw7wXa94 7UVjXFxx4OquebE0A2rCUfQ3vAZViS/BKvOOVWl86R4McOn9f8yJhaTYRPIqLGr1JeCu weJw== X-Gm-Message-State: AOAM530MHLjLH1P1Y1Caet8IqNiWKHJ+hxN704X29J1DinV6e5y8+tDh xBdPG84BRnmKucZwRecZiiw= X-Received: by 2002:ac8:3529:: with SMTP id y38mr11535559qtb.315.1590355701143; Sun, 24 May 2020 14:28:21 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id d14sm3665729qkg.25.2020.05.24.14.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 14:28:20 -0700 (PDT) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Cc: Nick Desaulniers , Fangrui Song , Dmitry Golovin , clang-built-linux@googlegroups.com, Ard Biesheuvel , Masahiro Yamada , Daniel Kiper , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] x86/boot: Remove runtime relocations from head_{32,64}.S Date: Sun, 24 May 2020 17:28:15 -0400 Message-Id: <20200524212816.243139-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The BFD linker generates runtime relocations for z_input_len and z_output_len, even though they are absolute symbols. Work around this 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 runtime relocations in the head code and allows us to drop the -z noreloc-overflow flag to the linker. Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/Makefile | 8 -------- arch/x86/boot/compressed/head_32.S | 17 ++++++++--------- arch/x86/boot/compressed/head_64.S | 4 ++-- arch/x86/boot/compressed/mkpiggy.c | 6 ++++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index aa9ed814e5fa..d3e882e855ee 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -49,15 +49,7 @@ UBSAN_SANITIZE :=n KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. -ifeq ($(CONFIG_X86_32),y) KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) -else -# To build 64-bit compressed kernel as PIE, we disable relocation -# overflow check to avoid relocation overflow error with a new linker -# command-line option, -z noreloc-overflow. -KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ - && echo "-z noreloc-overflow -pie --no-dynamic-linker") -endif LDFLAGS_vmlinux := -T hostprogs := mkpiggy diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 66657bb99aae..064e895bad92 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -193,18 +193,17 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) /* * Do the extraction, and jump to the new kernel.. */ - /* push arguments for extract_kernel: */ - pushl $z_output_len /* decompressed length, end of relocs */ + /* push arguments for extract_kernel: */ - pushl %ebp /* output address */ - - pushl $z_input_len /* input_len */ + pushl output_len@GOTOFF(%ebx) /* decompressed length, end of relocs */ + pushl %ebp /* output address */ + pushl input_len@GOTOFF(%ebx) /* input_len */ leal input_data@GOTOFF(%ebx), %eax - pushl %eax /* input_data */ + pushl %eax /* input_data */ leal boot_heap@GOTOFF(%ebx), %eax - pushl %eax /* heap area */ - pushl %esi /* real mode pointer */ - call extract_kernel /* returns kernel location in %eax */ + pushl %eax /* heap area */ + pushl %esi /* real mode pointer */ + call extract_kernel /* returns kernel location in %eax */ addl $24, %esp /* diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index f6ba32cd5702..6e4704b6a94e 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -508,9 +508,9 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) movq %rsi, %rdi /* real mode address */ leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ leaq input_data(%rip), %rdx /* input_data */ - movl $z_input_len, %ecx /* input_len */ + movl input_len(%rip), %ecx /* input_len */ movq %rbp, %r8 /* output target address */ - movl $z_output_len, %r9d /* decompressed length, end of relocs */ + movl output_len(%rip), %r9d /* decompressed length, end of relocs */ call extract_kernel /* returns kernel location in %rax */ popq %rsi diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c index 7e01248765b2..52aa56cdbacc 100644 --- a/arch/x86/boot/compressed/mkpiggy.c +++ b/arch/x86/boot/compressed/mkpiggy.c @@ -60,6 +60,12 @@ int main(int argc, char *argv[]) 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) -- 2.26.2