diff mbox series

build: Fix linker script for builtin Kernel

Message ID 20201210210037.16660-1-klaus@linux.vnet.ibm.com
State Accepted
Headers show
Series build: Fix linker script for builtin Kernel | expand

Commit Message

Klaus Heinrich Kiwi Dec. 10, 2020, 9 p.m. UTC
Commit '6b08928d - build/lds: place debug sections according to
defaults' introduced a DEBUG_SECTIONS macro that is effectivelly
resetting the location pointer back to zero, making the next section
(builtin_kernel) collide with the earlier sections.

Fix by moving these sections to the very end.

Error message:
$ make KERNEL=zImage.epapr
        [CC]  asm/asm-offsets.s
        [GN]  include/asm-offsets.h
<...>
        [LD]  skiboot.tmp.elf
ld: section .builtin_kernel LMA [0000000000000000,0000000000285d87]
 overlaps section .head LMA [0000000000000000,0000000000003897]
ld: section .naca LMA [0000000000004000,000000000000505f] overlaps
 section .builtin_kernel LMA [0000000000000000,0000000000285d87]
make: *** [/skiboot/Makefile.main:333: skiboot.tmp.elf] Error 1

Fixes: 6b08928d - build/lds: place debug sections according to defaults
Signed-off-by: Klaus Heinrich Kiwi <klaus@linux.vnet.ibm.com>
---
 skiboot.lds.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Klaus Heinrich Kiwi Dec. 11, 2020, 12:47 a.m. UTC | #1
On 12/10/2020 6:00 PM, Klaus Heinrich Kiwi wrote:

>   	/* Optional kernel image */
>          . = ALIGN(PAGE_SIZE);
>          .builtin_kernel : {
> @@ -243,6 +241,8 @@ SECTIONS
>   		__builtin_kernel_end = .;
>   	}
> 
> +	DEBUG_SECTIONS
> +

FYI, an IBM colleague from the compiler team (Segher) mentioned we could add (NOLOAD)
to the sections undere DEBUG_SECTIONS macro instead, and that could save us some
memory as well..

I'll test this tomorrow and send a V2 if successful.

But thoughts are welcome.

  -Klaus
Klaus Heinrich Kiwi Dec. 11, 2020, 11:18 a.m. UTC | #2
On 12/10/2020 9:47 PM, Klaus Heinrich Kiwi wrote:
> 
> 
> On 12/10/2020 6:00 PM, Klaus Heinrich Kiwi wrote:
> 
>>       /* Optional kernel image */
>>          . = ALIGN(PAGE_SIZE);
>>          .builtin_kernel : {
>> @@ -243,6 +241,8 @@ SECTIONS
>>           __builtin_kernel_end = .;
>>       }
>>
>> +    DEBUG_SECTIONS
>> +
> 
> FYI, an IBM colleague from the compiler team (Segher) mentioned we could add (NOLOAD)
> to the sections undere DEBUG_SECTIONS macro instead, and that could save us some
> memory as well..
> 
> I'll test this tomorrow and send a V2 if successful.

I did a few tests with the (NOLOAD) for the debug sections, but that alone wasn't sufficient
to fix original issue.. additionally, I couldn't note any memory / size differences in the final
binary.

So unless Segher has other suggestions, I think we will need the patch above after all.

Thanks,


>   -Klaus
Segher Boessenkool Dec. 11, 2020, 5:31 p.m. UTC | #3
On Fri, Dec 11, 2020 at 08:18:30AM -0300, Klaus Heinrich Kiwi wrote:
> On 12/10/2020 9:47 PM, Klaus Heinrich Kiwi wrote:
> >On 12/10/2020 6:00 PM, Klaus Heinrich Kiwi wrote:
> >
> >>      /* Optional kernel image */
> >>         . = ALIGN(PAGE_SIZE);
> >>         .builtin_kernel : {
> >>@@ -243,6 +241,8 @@ SECTIONS
> >>          __builtin_kernel_end = .;
> >>      }
> >>
> >>+    DEBUG_SECTIONS
> >>+
> >
> >FYI, an IBM colleague from the compiler team (Segher) mentioned we could 
> >add (NOLOAD)
> >to the sections undere DEBUG_SECTIONS macro instead, and that could save 
> >us some
> >memory as well..
> >
> >I'll test this tomorrow and send a V2 if successful.
> 
> I did a few tests with the (NOLOAD) for the debug sections, but that alone 
> wasn't sufficient
> to fix original issue.. additionally, I couldn't note any memory / size 
> differences in the final
> binary.
> 
> So unless Segher has other suggestions, I think we will need the patch 
> above after all.

Flags are inherited from the previous section if you specify nothing,
so I thought that was what caused the problem if you have the debug
sections before everything else.  Just putting the debug sections after
other sections instead of before (just like every other project does)
is probably a good idea no matter what...  but figuring out what went
wrong is at least fun for a Friday, isn't it?  :-)


Segher
Vasant Hegde Dec. 16, 2020, 7:57 a.m. UTC | #4
On 12/11/20 2:30 AM, Klaus Heinrich Kiwi wrote:
> Commit '6b08928d - build/lds: place debug sections according to
> defaults' introduced a DEBUG_SECTIONS macro that is effectivelly
> resetting the location pointer back to zero, making the next section
> (builtin_kernel) collide with the earlier sections.
> 
> Fix by moving these sections to the very end.

Thanks! Merged to master as a98262ee.

-Vasant
diff mbox series

Patch

diff --git a/skiboot.lds.S b/skiboot.lds.S
index 5da6f9d8..5a7f9e31 100644
--- a/skiboot.lds.S
+++ b/skiboot.lds.S
@@ -233,8 +233,6 @@  SECTIONS
 
 	ASSERT((HEAP_BASE - SKIBOOT_BASE) >= _end, "Heap collision with image")
 
-	DEBUG_SECTIONS
-
 	/* Optional kernel image */
        . = ALIGN(PAGE_SIZE);
        .builtin_kernel : {
@@ -243,6 +241,8 @@  SECTIONS
 		__builtin_kernel_end = .;
 	}
 
+	DEBUG_SECTIONS
+
 	/* Discards */
 	/DISCARD/ : {
 		*(.note.GNU-stack)