Skip to contentSkip to conversation

powerpc/boot: Delete unneeded .globl _zimage_start

PATCH Superseded Fangrui Song 5 participants 6 messages Mar 25, 2020 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/boot: Delete unneeded .globl _zimage_start

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

Fixes cd197ffcf10b "[POWERPC] zImage: Cleanup and improve zImage entry point"
Fixes ee9d21b3b358 "powerpc/boot: Ensure _zimage_start is a weak symbol"
Cc Joel Stanley <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/powerpc/boot/crt0.S | 3 ---
 1 file changed, 3 deletions(-)
arch/powerpc/boot/crt0.S +0 -3
index 92608f34d312..1d83966f5ef6 100644
@@ -44,9 +44,6 @@ p_end:		.long	_end
 p_pstack:	.long	_platform_stack_top
 #endif
 
-	.globl	_zimage_start
-	/* Clang appears to require the .weak directive to be after the symbol
-	 * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
 	.weak	_zimage_start
 _zimage_start:
 	.globl	_zimage_start_lib
Signature · 1 line
2.25.1.696.g5e7596f4ac-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Fangrui Song

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

Fixes cd197ffcf10b "[POWERPC] zImage: Cleanup and improve zImage entry point"
Fixes ee9d21b3b358 "powerpc/boot: Ensure _zimage_start is a weak symbol"
Cc Joel Stanley <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/powerpc/boot/crt0.S | 3 ---
 1 file changed, 3 deletions(-)
arch/powerpc/boot/crt0.S +0 -0
index 92608f34d312..1d83966f5ef6 100644

arch/powerpc/boot/crt0.S p_end: .long _end · line 48

Quoted 8 lines
arch/powerpc/boot/crt0.S +0 -3
@@ -44,9 +44,6 @@ p_end:                .long   _end
 p_pstack:      .long   _platform_stack_top
 #endif
 
-       .globl  _zimage_start
-       /* Clang appears to require the .weak directive to be after the symbol
-        * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
        .weak   _zimage_start
 _zimage_start:

Your explanation makes sense to me. I've added Alan to cc for his review.

Thanks for the patch.

Cheers,

Joel

Quoted 4 lines
arch/powerpc/boot/crt0.S +0 -1
        .globl  _zimage_start_lib
--

2.25.1.696.g5e7596f4ac-goog

#4 lore raw
In reply to Fangrui Song
Quoted 4 lines · Fangrui Song

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

Nothing is "overridden".

The as manual says (.weak):

This directive sets the weak attribute on the comma separated list of symbol 'names'. If the symbols do not already exist, they will be created.

so this behaviour is obviously as intended (or was later documented in any case), so LLVM has a bug to fix (whether you like this (much saner) behaviour or not).

Segher

#2 lore raw
In reply to Joel Stanley
Quoted 6 lines · Joel Stanley
Quoted 5 lines · Fangrui Song

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

No, it isn't accidental. gas deliberately lets .weak override .globl. Since 1996-07-26, git commit 5ca547dc239

I'm fine with the patch so far as it is true that there is no need for both .globl and .weak (and it looks silly to have both), but the explanation isn't true. The patch is needed because the clang assembler is incompatible with gas in this detail.

Quoted 39 lines
Quoted 17 lines
Fixes cd197ffcf10b "[POWERPC] zImage: Cleanup and improve zImage entry point"
Fixes ee9d21b3b358 "powerpc/boot: Ensure _zimage_start is a weak symbol"
Cc Joel Stanley <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/powerpc/boot/crt0.S | 3 ---
 1 file changed, 3 deletions(-)
arch/powerpc/boot/crt0.S +0 -0
index 92608f34d312..1d83966f5ef6 100644

arch/powerpc/boot/crt0.S p_end: .long _end · line 48

Quoted 8 lines
arch/powerpc/boot/crt0.S +0 -3
@@ -44,9 +44,6 @@ p_end:                .long   _end
 p_pstack:      .long   _platform_stack_top
 #endif
 
-       .globl  _zimage_start
-       /* Clang appears to require the .weak directive to be after the symbol
-        * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
        .weak   _zimage_start
 _zimage_start:

Your explanation makes sense to me. I've added Alan to cc for his review.

Thanks for the patch.

Cheers,

Joel

Quoted 3 lines
arch/powerpc/boot/crt0.S +0 -1
        .globl  _zimage_start_lib
--

2.25.1.696.g5e7596f4ac-goog

Signature · 2 lines
Alan Modra
Australia Development Lab, IBM
#5 lore raw
In reply to Fangrui Song
Quoted 9 lines · Fangrui Song

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

Fixes cd197ffcf10b "[POWERPC] zImage: Cleanup and improve zImage entry point"
Fixes ee9d21b3b358 "powerpc/boot: Ensure _zimage_start is a weak symbol"

So it seems the patch is OK but people don't agree with the explanation in the changelog.

Please send a v2 that captures the responses from Segher and Alan.

cheers

Quoted 16 lines
arch/powerpc/boot/crt0.S +0 -3
index 92608f34d312..1d83966f5ef6 100644
@@ -44,9 +44,6 @@ p_end:		.long	_end
 p_pstack:	.long	_platform_stack_top
 #endif
 
-	.globl	_zimage_start
-	/* Clang appears to require the .weak directive to be after the symbol
-	 * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
 	.weak	_zimage_start
 _zimage_start:
 	.globl	_zimage_start_lib
Signature · 1 line
2.25.1.696.g5e7596f4ac-goog
#3 lore raw
In reply to Alan Modra
Quoted 10 lines · Alan Modra
Quoted 6 lines · Joel Stanley
Quoted 5 lines · Fangrui Song

.globl sets the symbol binding to STB_GLOBAL while .weak sets the binding to STB_WEAK. They should not be used together. It is accidetal rather then intentional that GNU as let .weak override .globl while clang integrated assembler let the last win.

No, it isn't accidental. gas deliberately lets .weak override .globl. Since 1996-07-26, git commit 5ca547dc239

Fair. I am sadded by this commit.

% sed -n 'N;/.globl.*\n.*.weak/p;D' binutils-gdb/gas/testsuite/**/*(.)

I checked all occurrences and none is a real test excercising the behavior (.weak override .globl). All seem accidental.

It is unclear that clang integrated assembler should copy this behavior, though. For the record, I asked on [email protected] whether the assembler should error when .weak/.local can override a previous binding directive. It was rejected
https://sourceware.org/pipermail/binutils/2020-March/110376.html

On the clang integrated assembler side, we may try building things with an error or leave the overriding behavior as is.

Quoted 4 lines

I'm fine with the patch so far as it is true that there is no need for both .globl and .weak (and it looks silly to have both), but the explanation isn't true. The patch is needed because the clang assembler is incompatible with gas in this detail.

Since using one of .weak|.globl is nearly well-known, I'll send PATCH v2 with the description updated.

Quoted 11 lines · Segher Boessenkool

Nothing is "overridden".

The as manual says (.weak):

This directive sets the weak attribute on the comma separated list of symbol 'names'. If the symbols do not already exist, they will be created.

so this behaviour is obviously as intended (or was later documented in any case), so LLVM has a bug to fix (whether you like this (much saner) behaviour or not).

I will probably not call this a bug. I have recently discovered other discrepancy for which I think copying gas behaviors can just clutter up the code. We may need our own assembler documentation at some point.

Quoted 43 lines
Quoted 39 lines
Quoted 17 lines
Fixes cd197ffcf10b "[POWERPC] zImage: Cleanup and improve zImage entry point"
Fixes ee9d21b3b358 "powerpc/boot: Ensure _zimage_start is a weak symbol"
Cc Joel Stanley <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nick Desaulniers <[email protected]>
---
 arch/powerpc/boot/crt0.S | 3 ---
 1 file changed, 3 deletions(-)
arch/powerpc/boot/crt0.S +0 -0
index 92608f34d312..1d83966f5ef6 100644

arch/powerpc/boot/crt0.S p_end: .long _end · line 48

Quoted 8 lines
arch/powerpc/boot/crt0.S +0 -3
@@ -44,9 +44,6 @@ p_end:                .long   _end
 p_pstack:      .long   _platform_stack_top
 #endif
 
-       .globl  _zimage_start
-       /* Clang appears to require the .weak directive to be after the symbol
-        * is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
        .weak   _zimage_start
 _zimage_start:

Your explanation makes sense to me. I've added Alan to cc for his review.

Thanks for the patch.

Cheers,

Joel

Quoted 3 lines
arch/powerpc/boot/crt0.S +0 -1
        .globl  _zimage_start_lib
--

2.25.1.696.g5e7596f4ac-goog

Signature · 2 lines
Alan Modra
Australia Development Lab, IBM