From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 882B9C433EF for ; Fri, 14 Jan 2022 16:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fUtBCEjdjJmXLAq34CL1+JRkSZQywBOBd+SROfnf6Jo=; b=gdE1oXuJQad2YB e3NmNOAOQKfpV5Cq3gyIEPnlzg0UubaRuXECKIZ8n7+xNRCUTGmUrhEJP6hjRQCcjBCYFpfYagDc0 tSc9RiiUCPmqlVbOgi8EZWucFBhHYC2N5iOktc9ceISc0+NPxdgP25uaUrKgdtI8f3mK42EbbXLFd 975lV6Vxp4bcxPwpkvOy24ciFlf2vsOBiWQln8JWbN2uzKc1g+nZSAPlQQax3Z2k0XAHKhq6HL6kb HFyWnKBaT/LuVtXh8yNHM5GKNJCZdNYuHN+1fShk75HF35VJ4JIGG3dzB4VuwPrbObc8aJhnMRFep Fq22ZZJ3q9+oLjl2EJRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8P42-009gA2-2z; Fri, 14 Jan 2022 16:04:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8P3y-009g9F-3v for linux-arm-kernel@lists.infradead.org; Fri, 14 Jan 2022 16:04:27 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6B776D; Fri, 14 Jan 2022 08:04:24 -0800 (PST) Received: from [10.57.67.190] (unknown [10.57.67.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ADE9E3F766; Fri, 14 Jan 2022 08:04:23 -0800 (PST) Message-ID: Date: Fri, 14 Jan 2022 16:04:19 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [bootwrapper PATCH v2 11/13] Announce locations of memory objects Content-Language: en-GB To: Andre Przywara , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, Jaxson.Han@arm.com, vladimir.murzin@arm.com, Wei.Chen@arm.com References: <20220114105653.3003399-1-mark.rutland@arm.com> <20220114105653.3003399-12-mark.rutland@arm.com> <20220114153053.658a5ffa@donnerap.cambridge.arm.com> From: Robin Murphy In-Reply-To: <20220114153053.658a5ffa@donnerap.cambridge.arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220114_080426_292243_8700B1D0 X-CRM114-Status: GOOD ( 21.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022-01-14 15:30, Andre Przywara wrote: > On Fri, 14 Jan 2022 10:56:51 +0000 > Mark Rutland wrote: > > Hi Mark, > >> To make it easier to debug boot failures, log the location of memory >> objects at boot time. >> >> This is logged to the serial console as: >> >> | Boot-wrapper v0.2 >> | Entered at EL3 >> | Memory layout: >> | [0000000080000000..0000000080001f90] => boot-wrapper >> | [000000008000fff8..0000000080010000] => mbox >> | [0000000080200000..00000000822af200] => kernel >> | [0000000088000000..0000000088002857] => dtb >> >> Signed-off-by: Mark Rutland >> --- >> common/init.c | 27 +++++++++++++++++++++++++++ >> common/platform.c | 13 +++++++++++++ >> include/platform.h | 2 ++ >> model.lds.S | 20 ++++++++++++++------ >> 4 files changed, 56 insertions(+), 6 deletions(-) >> >> diff --git a/common/init.c b/common/init.c >> index 2600f73..fc74b9e 100644 >> --- a/common/init.c >> +++ b/common/init.c >> @@ -14,6 +14,32 @@ static void announce_bootwrapper(void) >> print_string("Boot-wrapper v0.2\r\n"); >> } >> >> +#define announce_object(object, desc) \ >> +do { \ >> + extern char object##__start[]; \ >> + extern char object##__end[]; \ >> + print_string("["); \ >> + print_ulong_hex((unsigned long)object##__start); \ >> + print_string(".."); \ >> + print_ulong_hex((unsigned long)object##__end); \ >> + print_string("] => " desc "\r\n"); \ >> +} while (0) >> + >> +static void announce_objects(void) >> +{ >> + print_string("Memory layout:\r\n"); >> + announce_object(text, "boot-wrapper"); >> + announce_object(mbox, "mbox"); >> + announce_object(kernel, "kernel"); >> +#ifdef XEN >> + announce_object(xen, "xen"); >> +#endif >> + announce_object(dtb, "dtb"); >> +#ifdef USE_INITRD >> + announce_object(filesystem, "initrd"); >> +#endif >> +} >> + >> void announce_arch(void); >> >> void cpu_init_bootwrapper(void) >> @@ -22,6 +48,7 @@ void cpu_init_bootwrapper(void) >> init_uart(); >> announce_bootwrapper(); >> announce_arch(); >> + announce_objects(); >> print_string("\r\n"); >> init_platform(); >> } >> diff --git a/common/platform.c b/common/platform.c >> index 80d0562..26e5944 100644 >> --- a/common/platform.c >> +++ b/common/platform.c >> @@ -52,6 +52,19 @@ void print_string(const char *str) >> print_char(*str++); >> } >> >> +#define HEX_CHARS_PER_LONG (2 * sizeof(long)) >> + >> +void print_ulong_hex(unsigned long val) >> +{ >> + const char hex_chars[16] = "0123456789abcdef"; > > This breaks the build for me (I guess because of the const?): > ------------------- > ld --gc-sections arch/aarch64/boot.o arch/aarch64/stack.o arch/aarch64/utils.o arch/aarch64/init.o arch/aarch64/psci.o common/boot.o common/bakery_lock.o common/platform.o common/lib.o common/init.o common/psci.o common/gic-v3.o -o linux-system.axf --script=model.lds > ld: common/platform.o: in function `print_ulong_hex': > /src/boot-wrapper-aarch64.git/common/platform.c:58: undefined reference to `__stack_chk_guard' > ld: /src/boot-wrapper-aarch64.git/common/platform.c:58: undefined reference to `__stack_chk_guard' > ld: /src/boot-wrapper-aarch64.git/common/platform.c:66: undefined reference to `__stack_chk_fail' > /src/boot-wrapper-aarch64.git/common/platform.c:66:(.text.print_ulong_hex+0xa0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `__stack_chk_fail' > make: *** [Makefile:684: linux-system.axf] Error 1 > ------------------ I got curious and tried a quick test compiling this function in isolation, and indeed for some reason GCC (9.3.0 at -O2) seems to end up allocating 80 bytes of stack, which is apparently large enough to trigger insertion of a stack check, and laboriously copying the string from static data into it. FWIW either making hex_chars static const, or simply '#define hex_chars "01234567abcdef"', not only avoids a stack check but also leads to notably nicer code. Of course, something like "print_char(v + (v > 9 ? 'a' : '0'));" is best of all in terms of code/data, but risks venturing into "too clever" territory. Robin. > Adding -fno-stack-protector fixes it again. > > I am still checking on each one of those compiler options, shall I send a > smaller version of that patch 3/9 of mine, meanwhile, just carrying the > uncontested -ffreestanding and -nostdlib, plus -fno-stack-protector? > > Cheers, > Andre > >> + int i; >> + >> + for (i = HEX_CHARS_PER_LONG - 1; i >= 0; i--) { >> + int v = (val >> (4 * i)) & 0xf; >> + print_char(hex_chars[v]); >> + } >> +} >> + >> void init_uart(void) >> { >> /* >> diff --git a/include/platform.h b/include/platform.h >> index 237b481..c88e124 100644 >> --- a/include/platform.h >> +++ b/include/platform.h >> @@ -11,6 +11,8 @@ >> >> void print_char(char c); >> void print_string(const char *str); >> +void print_ulong_hex(unsigned long val); >> + >> void init_uart(void); >> >> void init_platform(void); >> diff --git a/model.lds.S b/model.lds.S >> index d4e7e13..dacaa25 100644 >> --- a/model.lds.S >> +++ b/model.lds.S >> @@ -35,46 +35,54 @@ SECTIONS >> * the boot section's *(.data) >> */ >> .kernel (PHYS_OFFSET + KERNEL_OFFSET): { >> - kernel = .; >> + kernel__start = .; >> KERNEL >> + kernel__end = .; >> } >> >> #ifdef XEN >> .xen (PHYS_OFFSET + XEN_OFFSET): { >> - xen = .; >> + xen__start = .; >> XEN >> + xen__end = .; >> } >> >> - entrypoint = xen; >> + entrypoint = xen__start; >> #else >> - entrypoint = kernel; >> + entrypoint = kernel__start; >> #endif >> >> .dtb (PHYS_OFFSET + FDT_OFFSET): { >> + dtb__start = .; >> dtb = .; >> ./fdt.dtb >> + dtb__end = .; >> } >> >> #ifdef USE_INITRD >> .filesystem (PHYS_OFFSET + FS_OFFSET): { >> - filesystem = .; >> + filesystem__start = .; >> FILESYSTEM >> - fs_size = . - filesystem; >> + filesystem__end = .; >> } >> #endif >> >> .boot PHYS_OFFSET: { >> + text__start = .; >> *(.init) >> *(.text*) >> *(.data* .rodata* .bss* COMMON) >> *(.vectors) >> *(.stack) >> PROVIDE(etext = .); >> + text__end = .; >> } >> >> .mbox (PHYS_OFFSET + MBOX_OFFSET): { >> + mbox__start = .; >> mbox = .; >> QUAD(0x0) >> + mbox__end = .; >> } >> >> ASSERT(etext <= (PHYS_OFFSET + TEXT_LIMIT), ".text overflow!") > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel