Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1424617ybs; Mon, 25 May 2020 16:03:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2IAWimWREbVdkltc+YfFAcrIfGsG7uFP4LjWefnnYZFcxmnbRrHOPhhfZbKyxcKBl5C28 X-Received: by 2002:a17:906:44f:: with SMTP id e15mr19724652eja.161.1590447825400; Mon, 25 May 2020 16:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590447825; cv=none; d=google.com; s=arc-20160816; b=y506Mm7iFtculd8/iPZsvrwmF+FiGcQ3Ixj/+tCV8/xZucdqaZXfxCKQtIwpBy4Zjk QB5eHOUxqInujm/nuHjCkB3aleLKAN3JfmRlBCjgvw3Yg5UYjv54GvrYcx/P6JrYa0dY zspXqSCskNkJYu2O2PmLefGvTFnGQDLGcxrXXs0kez4F8yLqV4zwSTDineJANBJwvue8 ojbgsrk9pZRIAwrm4vVHztsVxKxxaga3S5qDYSquykOeSsJgTyoalbW6KvqWDvaGpBz5 h1HmLIevjudf9LkySwOUT8bxaalJKeHIF5yItZHnLiKv7JSEJub4n1u+dkWzrbtkPBZ3 ASQA== 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=7ShMtyQLISvfKbiu0RdR0JtG8pe3pv3Pngvw21N+oGo=; b=GUWq/l6+GI9x59J6331umllWpPGveGykFcmgm0yFDkDORtZzsoV26KFJXyNfQu1LZH +O7OaCD2LXc31FGwlcoahG2RUmogyks8tgBTMFswPjeyuIoTyRrkXpB7s3/lzbMgj7yn siyl27vI1KJ903jpzZ0NIRdj5cLZad2UH4eJzp016+zJeF8+dRSrZh9Na74MzMuJJE/9 1zoK8Q/uGwsSYjHUPB0c3VXF4D55JB7xG6Tt1DtirLFY2mVnRq//r63CBc1E5Lw191+i c5CfHoL0Ix2eFc+ziglpwpz8UhSOvcqLyXwjVGyT+5TILPRWSxq8nhXiUoo2VnIocaxT G4NQ== 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 lz8si10756818ejb.721.2020.05.25.16.03.22; Mon, 25 May 2020 16:03:45 -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 S1730364AbgEYW7Z (ORCPT + 99 others); Mon, 25 May 2020 18:59:25 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:43991 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730062AbgEYW7Y (ORCPT ); Mon, 25 May 2020 18:59:24 -0400 Received: by mail-qt1-f196.google.com with SMTP id o19so14775077qtr.10 for ; Mon, 25 May 2020 15:59:23 -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=7ShMtyQLISvfKbiu0RdR0JtG8pe3pv3Pngvw21N+oGo=; b=RCsLKrIeSgph+Eu4yGPW3w8mdbetiNYrUL3371vjhw/A+I3aLTK9xjUSbd4n4Ba9RW l+9yZpsvjQyPNDHKzayjzjuPZUA2DJ53gO2HrArbeC/2AvVkBND5Q97a1ctjLgY2+IDo HfRE8PKzfbcOx1MqHVthSuqIBm1qgrVrvi2UNHSaDPEZ6VKRxYBRxhLvVw683qDFhLWH AdtVpBEIJ6l5POWR7yAMcExpnEbOqOzj5NKdF0In9brHAb1jmywTp9WI3llfGqENf4Hx obRzIpQzQh+CTFasT5f3170S9qKFEUc0R2qBZw4TurcLHL9gsFgW3oIn6pdz85Hsi9S3 0aMQ== X-Gm-Message-State: AOAM532209RMs15l+xQtzQM6aa0Eb5UPtWbuVn3x9LI4RXv7oLTwqBOM M+lL8EazvUSbEQto8rQHqyg= X-Received: by 2002:ac8:4542:: with SMTP id z2mr7617038qtn.90.1590447562654; Mon, 25 May 2020 15:59:22 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id d140sm15024585qkc.22.2020.05.25.15.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 15:59:22 -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 v2 3/4] x86/boot: Remove runtime relocations from head_{32,64}.S Date: Mon, 25 May 2020 18:59:17 -0400 Message-Id: <20200525225918.1624470-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200524212816.243139-1-nivedita@alum.mit.edu> References: <20200524212816.243139-1-nivedita@alum.mit.edu> 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. 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 runtime relocations in the head code and allows us to drop the -z noreloc-overflow flag to the linker. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=25754 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 18b0edcb23d2..4b7ad1dfbea6 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -517,9 +517,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