Skip to contentSkip to conversation

Fixes for clang/lld

PATCH New Bill Wendling 3 participants 24 messages Oct 17, 2020 – Nov 27, 2020 PowerPC

lore
Share & tools
lore
#2 lore raw

PATCH 2/2 powerpc/boot: Use clang when CC is clang

In reply to Bill Wendling

The gcc compiler may not be available if CC is clang.

Cc Fangrui Song <[email protected]>
Cc Alan Modra <[email protected]>
---
 arch/powerpc/boot/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/boot/Makefile +4 -0
index b88fd27a45f0..218f1c9adb5b 100644
@@ -21,7 +21,11 @@
 all: $(obj)/zImage
 
 ifdef CROSS32_COMPILE
+ifdef CONFIG_CC_IS_CLANG
+    BOOTCC := $(CROSS32_COMPILE)clang
+else
     BOOTCC := $(CROSS32_COMPILE)gcc
+endif
     BOOTAR := $(CROSS32_COMPILE)ar
 else
     BOOTCC := $(CC)
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#1 lore raw

PATCH 1/2 powerpc/wrapper: Add "-z notext" flag to disable diagnostic

In reply to Bill Wendling

The "-z notext" flag disables reporting an error if DT_TEXTREL is set.

ld.lld: error: can't create dynamic relocation R_PPC64_ADDR64 against
symbol: _start in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

defined in
referenced by crt0.o:(.text+0x8) in archive arch/powerpc/boot/wrapper.a

The BFD linker disables this by default (though it's configurable in current versions). LLD enables this by default. So we add the flag to keep LLD from emitting the error.

Cc Fangrui Song <[email protected]>
Cc Alan Modra <[email protected]>
---
 arch/powerpc/boot/wrapper | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/boot/wrapper +4 -2
index cd58a62e810d..e576d3e4b23f 100755
@@ -46,6 +46,7 @@ compression=.gz
 uboot_comp=gzip
 pie=
 format=
+notext=
 
 # cross-compilation prefix
 CROSS=
@@ -353,6 +354,7 @@ epapr)
     platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
     link_address='0x20000000'
     pie=-pie
+    notext='-z notext'
     ;;
 mvme5100)
     platformo="$object/fixed-head.o $object/mvme5100.o"
@@ -493,8 +495,8 @@ if [ "$platform" != "miboot" ]; then
         text_start="-Ttext $link_address"
     fi
 #link everything
-    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" $map \
-	$platformo $tmp $object/wrapper.a
+    ${CROSS}ld -m $format -T $lds $text_start $pie $notext $nodl -o "$ofile" \
+        $map $platformo $tmp $object/wrapper.a
     rm $tmp
 fi
 
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#0 lore raw

cover Fixes for clang/lld

These patches fix some compilation / linking issues with clang & lld.

Bill Wendling (2):
powerpc/wrapper: Add "-z notext" flag to disable diagnostic powerpc/boot: Use clang when CC is clang

 arch/powerpc/boot/Makefile | 4 ++++
 arch/powerpc/boot/wrapper  | 6 ++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
#3 lore raw

PATCH 1/3 powerpc/wrapper: add "-z notext" flag to disable diagnostic

In reply to Bill Wendling

The "-z notext" flag disables reporting an error if DT_TEXTREL is set.

ld.lld: error: can't create dynamic relocation R_PPC64_ADDR64 against
symbol: _start in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

defined in
referenced by crt0.o:(.text+0x8) in archive arch/powerpc/boot/wrapper.a

The BFD linker disables this by default (though it's configurable in current versions). LLD enables this by default. So we add the flag to keep LLD from emitting the error.

Cc Fangrui Song <[email protected]>
Cc Alan Modra <[email protected]>
---
 arch/powerpc/boot/wrapper | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/boot/wrapper +3 -1
index e1194955adbb..41fa0a8715e3 100755
@@ -46,6 +46,7 @@ compression=.gz
 uboot_comp=gzip
 pie=
 format=
+notext=
 rodynamic=
 
 # cross-compilation prefix
@@ -354,6 +355,7 @@ epapr)
     platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
     link_address='0x20000000'
     pie=-pie
+    notext='-z notext'
     rodynamic=$(if ${CROSS}ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
     ;;
 mvme5100)
@@ -495,7 +497,7 @@ if [ "$platform" != "miboot" ]; then
         text_start="-Ttext $link_address"
     fi
 #link everything
-    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic -o "$ofile" $map \
+    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic $notext -o "$ofile" $map \
 	$platformo $tmp $object/wrapper.a
     rm $tmp
 fi
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#4 lore raw

cover PPC: fixes for clang support

In reply to Bill Wendling

This series of patches include fixes for clang issues that arose. The "powerpc/64s" patch was "inspired" by a similar patch for ARM:

eb7c11ee3c5ce arm64: alternative: Work around .inst assembler bugs

Bill Wendling (3):
powerpc/wrapper: add "-z notext" flag to disable diagnostic powerpc/boot: Use clang when CC is clang powerpc/64s: feature: work around inline asm issues

 arch/powerpc/boot/Makefile                |  4 ++++
 arch/powerpc/boot/wrapper                 |  4 +++-
 arch/powerpc/include/asm/feature-fixups.h | 19 ++++++++++++++-----
 3 files changed, 21 insertions(+), 6 deletions(-)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#23 lore raw

PATCH 3/3 powerpc/64s: feature: work around inline asm issues

In reply to Bill Wendling

The clang toolchain treats inline assembly a bit differently than straight assembly code. In particular, inline assembly doesn't have the complete context available to resolve expressions. This is intentional to avoid divergence in the resulting assembly code.

We can work around this issue by borrowing a workaround done for ARM, i.e. not directly testing the labels themselves, but by moving the current output pointer by a value that should always be zero. If this value is not null, then we will trigger a backward move, which is explicitly forbidden.

---
 arch/powerpc/include/asm/feature-fixups.h | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/feature-fixups.h +14 -5
index b0af97add751..34331c4ba61a 100644
@@ -36,6 +36,18 @@ label##2:						\
 	.align 2;					\
 label##3:
 
+/*
+ * If the .org directive fails, it means that the feature instructions
+ * are smaller than the alternate instructions. This used to be written
+ * as
+ *
+ * .ifgt (label##4b-label##3b) - (label##2b-label##1b)
+ *      .error "Feature section else case larger than body"
+ * .endif
+ *
+ * but clang's assembler complains about the expression being non-absolute
+ * when the code appears in an inline assembly statement.
+ */
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)		\
 label##4:							\
 	.popsection;						\
@@ -48,11 +60,8 @@ label##5:							\
 	FTR_ENTRY_OFFSET label##2b-label##5b;			\
 	FTR_ENTRY_OFFSET label##3b-label##5b;			\
 	FTR_ENTRY_OFFSET label##4b-label##5b;			\
-	.ifgt (label##4b- label##3b)-(label##2b- label##1b);	\
-	.error "Feature section else case larger than body";	\
-	.endif;							\
-	.popsection;
-
+	.popsection;						\
+	.org . - ((label##4b-label##3b) > (label##2b-label##1b));
 
 /* CPU feature dependent sections */
 #define BEGIN_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#22 lore raw

PATCH 2/3 powerpc/boot: Use clang when CC is clang

In reply to Bill Wendling

The gcc compiler may not be available if CC is clang.

---
 arch/powerpc/boot/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/boot/Makefile +4 -0
index f8ce6d2dde7b..68a7534454cd 100644
@@ -21,7 +21,11 @@
 all: $(obj)/zImage
 
 ifdef CROSS32_COMPILE
+ifdef CONFIG_CC_IS_CLANG
+    BOOTCC := $(CROSS32_COMPILE)clang
+else
     BOOTCC := $(CROSS32_COMPILE)gcc
+endif
     BOOTAR := $(CROSS32_COMPILE)ar
 else
     BOOTCC := $(CC)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#7 lore raw

PATCH v3 3/3 powerpc/64s: feature: Work around inline asm issues

In reply to Bill Wendling

The clang toolchain treats inline assembly a bit differently than straight assembly code. In particular, inline assembly doesn't have the complete context available to resolve expressions. This is intentional to avoid divergence in the resulting assembly code.

We can work around this issue by borrowing a workaround done for ARM, i.e. not directly testing the labels themselves, but by moving the current output pointer by a value that should always be zero. If this value is not null, then we will trigger a backward move, which is explicitly forbidden.

---
 arch/powerpc/include/asm/feature-fixups.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/feature-fixups.h +13 -4
index b0af97add751..f81036518edb 100644
@@ -36,6 +36,18 @@ label##2:						\
 	.align 2;					\
 label##3:
 
+/*
+ * If the .org directive fails, it means that the feature instructions
+ * are smaller than the alternate instructions. This used to be written
+ * as
+ *
+ * .ifgt (label##4b-label##3b) - (label##2b-label##1b)
+ *      .error "Feature section else case larger than body"
+ * .endif
+ *
+ * but clang's assembler complains about the expression being non-absolute
+ * when the code appears in an inline assembly statement.
+ */
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)		\
 label##4:							\
 	.popsection;						\
@@ -48,12 +60,9 @@ label##5:							\
 	FTR_ENTRY_OFFSET label##2b-label##5b;			\
 	FTR_ENTRY_OFFSET label##3b-label##5b;			\
 	FTR_ENTRY_OFFSET label##4b-label##5b;			\
-	.ifgt (label##4b- label##3b)-(label##2b- label##1b);	\
-	.error "Feature section else case larger than body";	\
-	.endif;							\
+	.org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
 	.popsection;
 
-
 /* CPU feature dependent sections */
 #define BEGIN_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
 #define BEGIN_FTR_SECTION		START_FTR_SECTION(97)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#6 lore raw

PATCH v3 2/3 powerpc/boot: Use clang when CC is clang

In reply to Bill Wendling

The gcc compiler may not be available if CC is clang.

---
 arch/powerpc/boot/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/powerpc/boot/Makefile +4 -0
index f8ce6d2dde7b..68a7534454cd 100644
@@ -21,7 +21,11 @@
 all: $(obj)/zImage
 
 ifdef CROSS32_COMPILE
+ifdef CONFIG_CC_IS_CLANG
+    BOOTCC := $(CROSS32_COMPILE)clang
+else
     BOOTCC := $(CROSS32_COMPILE)gcc
+endif
     BOOTAR := $(CROSS32_COMPILE)ar
 else
     BOOTCC := $(CC)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#5 lore raw

v3 cover PPC: fixes for clang support

In reply to Bill Wendling

Note: This is a resend of PPC/clang patches I sent before. The previous series had a bad title, and one of the patches had a typo in it.

This series of patches include fixes for clang issues that arose. The "powerpc/64s" patch was "inspired" by a similar patch for ARM:

eb7c11ee3c5ce arm64: alternative: Work around .inst assembler bugs

Bill Wendling (3):
powerpc/wrapper: add "-z notext" flag to disable diagnostic powerpc/boot: Use clang when CC is clang powerpc/64s: feature: Work around inline asm issues

 arch/powerpc/boot/Makefile                |  4 ++++
 arch/powerpc/boot/wrapper                 |  4 +++-
 arch/powerpc/include/asm/feature-fixups.h | 17 +++++++++++++----
 3 files changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#21 lore raw

PATCH 1/3 powerpc/wrapper: add "-z notext" flag to disable diagnostic

The "-z notext" flag disables reporting an error if DT_TEXTREL is set.

ld.lld: error: can't create dynamic relocation R_PPC64_ADDR64 against
symbol: _start in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

defined in
referenced by crt0.o:(.text+0x8) in archive arch/powerpc/boot/wrapper.a

The BFD linker disables this by default (though it's configurable in current versions). LLD enables this by default. So we add the flag to keep LLD from emitting the error.

Cc Fangrui Song <[email protected]>
Cc Alan Modra <[email protected]>
---
 arch/powerpc/boot/wrapper | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/boot/wrapper +3 -1
index e1194955adbb..41fa0a8715e3 100755
@@ -46,6 +46,7 @@ compression=.gz
 uboot_comp=gzip
 pie=
 format=
+notext=
 rodynamic=
 
 # cross-compilation prefix
@@ -354,6 +355,7 @@ epapr)
     platformo="$object/pseries-head.o $object/epapr.o $object/epapr-wrapper.o"
     link_address='0x20000000'
     pie=-pie
+    notext='-z notext'
     rodynamic=$(if ${CROSS}ld -V 2>&1 | grep -q LLD ; then echo "-z rodynamic"; fi)
     ;;
 mvme5100)
@@ -495,7 +497,7 @@ if [ "$platform" != "miboot" ]; then
         text_start="-Ttext $link_address"
     fi
 #link everything
-    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic -o "$ofile" $map \
+    ${CROSS}ld -m $format -T $lds $text_start $pie $nodl $rodynamic $notext -o "$ofile" $map \
 	$platformo $tmp $object/wrapper.a
     rm $tmp
 fi
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
#8 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

In reply to Bill Wendling

Hi Bill,

Quoted 40 lines · Bill Wendling

The clang toolchain treats inline assembly a bit differently than straight assembly code. In particular, inline assembly doesn't have the complete context available to resolve expressions. This is intentional to avoid divergence in the resulting assembly code.

We can work around this issue by borrowing a workaround done for ARM, i.e. not directly testing the labels themselves, but by moving the current output pointer by a value that should always be zero. If this value is not null, then we will trigger a backward move, which is explicitly forbidden.

---
 arch/powerpc/include/asm/feature-fixups.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/feature-fixups.h +12 -0
index b0af97add751..f81036518edb 100644
@@ -36,6 +36,18 @@ label##2:						\
 	.align 2;					\
 label##3:
 
+/*
+ * If the .org directive fails, it means that the feature instructions
+ * are smaller than the alternate instructions. This used to be written
+ * as
+ *
+ * .ifgt (label##4b-label##3b) - (label##2b-label##1b)
+ *      .error "Feature section else case larger than body"
+ * .endif
+ *
+ * but clang's assembler complains about the expression being non-absolute
+ * when the code appears in an inline assembly statement.
+ */
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)		\
 label##4:							\
 	.popsection;						\

arch/powerpc/include/asm/feature-fixups.h label##5: \ · line 64

Quoted 8 lines
arch/powerpc/include/asm/feature-fixups.h +1 -3
@@ -48,12 +60,9 @@ label##5:							\
 	FTR_ENTRY_OFFSET label##2b-label##5b;			\
 	FTR_ENTRY_OFFSET label##3b-label##5b;			\
 	FTR_ENTRY_OFFSET label##4b-label##5b;			\
-	.ifgt (label##4b- label##3b)-(label##2b- label##1b);	\
-	.error "Feature section else case larger than body";	\
-	.endif;							\
+	.org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
 	.popsection;

When I have an oversize alt section this doesn't seem to give me any error using binutils?

If I hard code:

	.org . - (1);

It fails as expected.

But if I hard code:

	.org . - (1 > 0);

It builds?

cheers

#9 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 11 lines · Michael Ellerman

If I hard code:

	.org . - (1);

It fails as expected.

But if I hard code:

	.org . - (1 > 0);

It builds?

"true" (as a result of a comparison) in as is -1, not 1.

Segher

#10 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

Quoted 18 lines · Segher Boessenkool
Quoted 11 lines · Michael Ellerman

If I hard code:

      .org . - (1);

It fails as expected.

But if I hard code:

      .org . - (1 > 0);

It builds?

"true" (as a result of a comparison) in as is -1, not 1.

Segher

#11 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

After looking at this, I suspect that the correct change should be:

  .org . + ((label##4b-label##3b) > (label##2b-label##1b));

I'm sorry about that. I can submit another version of the patch.

-bw

Quoted 24 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

Quoted 18 lines · Segher Boessenkool
Quoted 11 lines · Michael Ellerman

If I hard code:

      .org . - (1);

It fails as expected.

But if I hard code:

      .org . - (1 > 0);

It builds?

"true" (as a result of a comparison) in as is -1, not 1.

Segher

#12 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

In reply to Bill Wendling

(Please don't top-post.)

Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

- .ifgt (label##4b- label##3b)-(label##2b- label##1b); \
- .error "Feature section else case larger than body"; \
- .endif; \
+ .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \

It should be a + in that last line, not a -. Was this tested?

Segher

#13 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 16 lines · Segher Boessenkool
Quoted 4 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Quoted 2 lines

Was this tested?

Please don't be insulting. Anyone can make an error.

-bw

#14 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 12 lines · Bill Wendling
Quoted 10 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

Quoted 8 lines
Quoted 6 lines
arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \

It should be a + in that last line, not a -.

I said so in a follow up email.

Yeah, and that arrived a second after I pressed "send" :-)

Quoted 3 lines
Quoted 2 lines

Was this tested?

Please don't be insulting. Anyone can make an error.

Absolutely, but it is just a question. It seems you could improve that testing! It helps you yourself most of all ;-)

Segher

#15 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 18 lines · Segher Boessenkool
Quoted 17 lines · Bill Wendling
Quoted 15 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

(quoted diff) +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

-bw

#16 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 24 lines · Bill Wendling
Quoted 22 lines · Segher Boessenkool
Quoted 20 lines · Bill Wendling
Quoted 15 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

(quoted diff) +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Quoted 8 lines
Quoted 2 lines

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

I wanted to retain the nicer error reporting for gcc builds, so I did it like this:

arch/powerpc/include/asm/feature-fixups.h +19 -3
index b0af97add751..c4ad33074df5 100644
@@ -36,6 +36,24 @@ label##2:						\
 	.align 2;					\
 label##3:
 
+
+#ifndef CONFIG_CC_IS_CLANG
+#define CHECK_ALT_SIZE(else_size, body_size)			\
+	.ifgt (else_size) - (body_size);			\
+	.error "Feature section else case larger than body";	\
+	.endif;
+#else
+/*
+ * If we use the ifgt syntax above, clang's assembler complains about the
+ * expression being non-absolute when the code appears in an inline assembly
+ * statement.
+ * As a workaround use an .org directive that has no effect if the else case
+ * instructions are smaller than the body, but fails otherwise.
+ */
+#define CHECK_ALT_SIZE(else_size, body_size)			\
+	.org . + ((else_size) > (body_size));
+#endif
+
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)		\
 label##4:							\
 	.popsection;						\
@@ -48,9 +66,7 @@ label##5:							\
 	FTR_ENTRY_OFFSET label##2b-label##5b;			\
 	FTR_ENTRY_OFFSET label##3b-label##5b;			\
 	FTR_ENTRY_OFFSET label##4b-label##5b;			\
-	.ifgt (label##4b- label##3b)-(label##2b- label##1b);	\
-	.error "Feature section else case larger than body";	\
-	.endif;							\
+	CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
 	.popsection;
 
 

I've pushed a branch with all your patches applied to:

https://github.com/linuxppc/linux/commits/next-test

Are you able to give that a quick test? It builds clean with clang for me, but we must be using different versions of clang because my branch already builds clean for me even without your patches.

cheers

#17 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 78 lines · Michael Ellerman
Quoted 24 lines · Bill Wendling
Quoted 22 lines · Segher Boessenkool
Quoted 20 lines · Bill Wendling
Quoted 15 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Quoted 8 lines
Quoted 2 lines

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

I wanted to retain the nicer error reporting for gcc builds, so I did it like this:

arch/powerpc/include/asm/feature-fixups.h +19 -3
index b0af97add751..c4ad33074df5 100644
@@ -36,6 +36,24 @@ label##2:                                            \
        .align 2;                                       \
 label##3:
 
+
+#ifndef CONFIG_CC_IS_CLANG
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .ifgt (else_size) - (body_size);                        \
+       .error "Feature section else case larger than body";    \
+       .endif;
+#else
+/*
+ * If we use the ifgt syntax above, clang's assembler complains about the
+ * expression being non-absolute when the code appears in an inline assembly
+ * statement.
+ * As a workaround use an .org directive that has no effect if the else case
+ * instructions are smaller than the body, but fails otherwise.
+ */
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .org . + ((else_size) > (body_size));
+#endif
+
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)          \
 label##4:                                                      \
        .popsection;                                            \
@@ -48,9 +66,7 @@ label##5:                                                     \
        FTR_ENTRY_OFFSET label##2b-label##5b;                   \
        FTR_ENTRY_OFFSET label##3b-label##5b;                   \
        FTR_ENTRY_OFFSET label##4b-label##5b;                   \
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
        .popsection;
 
 
Quoted 4 lines

I've pushed a branch with all your patches applied to:

https://github.com/linuxppc/linux/commits/next-test

This works for me. Thanks!

Quoted 4 lines

Are you able to give that a quick test? It builds clean with clang for me, but we must be using different versions of clang because my branch already builds clean for me even without your patches.

You may need to set LLVM_IAS=1 to get the behavior I'm seeing. That turns on clang's integrated assembler, which I think is disabled by default.

Note that with clang's integrated assembler, arch/powerpc/boot/util.S fails to compile. Alan Modra mentioned that he sent you a patch to "modernize" the file so that clang can compile it.

-bw

#18 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 79 lines · Bill Wendling
Quoted 78 lines · Michael Ellerman
Quoted 24 lines · Bill Wendling
Quoted 22 lines · Segher Boessenkool
Quoted 20 lines · Bill Wendling
Quoted 15 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Quoted 8 lines
Quoted 2 lines

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

I wanted to retain the nicer error reporting for gcc builds, so I did it like this:

arch/powerpc/include/asm/feature-fixups.h +19 -3
index b0af97add751..c4ad33074df5 100644
@@ -36,6 +36,24 @@ label##2:                                            \
        .align 2;                                       \
 label##3:
 
+
+#ifndef CONFIG_CC_IS_CLANG
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .ifgt (else_size) - (body_size);                        \
+       .error "Feature section else case larger than body";    \
+       .endif;
+#else
+/*
+ * If we use the ifgt syntax above, clang's assembler complains about the
+ * expression being non-absolute when the code appears in an inline assembly
+ * statement.
+ * As a workaround use an .org directive that has no effect if the else case
+ * instructions are smaller than the body, but fails otherwise.
+ */
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .org . + ((else_size) > (body_size));
+#endif
+
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)          \
 label##4:                                                      \
        .popsection;                                            \
@@ -48,9 +66,7 @@ label##5:                                                     \
        FTR_ENTRY_OFFSET label##2b-label##5b;                   \
        FTR_ENTRY_OFFSET label##3b-label##5b;                   \
        FTR_ENTRY_OFFSET label##4b-label##5b;                   \
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
        .popsection;
 
 
Quoted 5 lines
Quoted 4 lines

I've pushed a branch with all your patches applied to:

https://github.com/linuxppc/linux/commits/next-test

This works for me. Thanks!

Great.

Quoted 7 lines
Quoted 4 lines

Are you able to give that a quick test? It builds clean with clang for me, but we must be using different versions of clang because my branch already builds clean for me even without your patches.

You may need to set LLVM_IAS=1 to get the behavior I'm seeing. That turns on clang's integrated assembler, which I think is disabled by default.

Yep that does it.

But then I get:
clang: error: unsupported argument '-mpower4' to option 'Wa,'
clang: error: unsupported argument '-many' to option 'Wa,'

So I guess I'm still missing something?

Quoted 3 lines

Note that with clang's integrated assembler, arch/powerpc/boot/util.S fails to compile. Alan Modra mentioned that he sent you a patch to "modernize" the file so that clang can compile it.

Ah you're right he did, it didn't go to patchwork so I missed it. Have grabbed it now.

cheers

#19 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

Quoted 97 lines · Michael Ellerman
Quoted 79 lines · Bill Wendling
Quoted 78 lines · Michael Ellerman
Quoted 24 lines · Bill Wendling
Quoted 22 lines · Segher Boessenkool
Quoted 20 lines · Bill Wendling
Quoted 15 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 2 lines · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison, you'll get a build error.

But that means your patch is the wrong way around?

arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) > (label##2b-label##1b)); \
Quoted 1 line

It should be a + in that last line, not a -.

I said so in a follow up email.

Quoted 8 lines
Quoted 2 lines

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

I wanted to retain the nicer error reporting for gcc builds, so I did it like this:

arch/powerpc/include/asm/feature-fixups.h +19 -3
index b0af97add751..c4ad33074df5 100644
@@ -36,6 +36,24 @@ label##2:                                            \
        .align 2;                                       \
 label##3:
 
+
+#ifndef CONFIG_CC_IS_CLANG
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .ifgt (else_size) - (body_size);                        \
+       .error "Feature section else case larger than body";    \
+       .endif;
+#else
+/*
+ * If we use the ifgt syntax above, clang's assembler complains about the
+ * expression being non-absolute when the code appears in an inline assembly
+ * statement.
+ * As a workaround use an .org directive that has no effect if the else case
+ * instructions are smaller than the body, but fails otherwise.
+ */
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .org . + ((else_size) > (body_size));
+#endif
+
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)          \
 label##4:                                                      \
        .popsection;                                            \
@@ -48,9 +66,7 @@ label##5:                                                     \
        FTR_ENTRY_OFFSET label##2b-label##5b;                   \
        FTR_ENTRY_OFFSET label##3b-label##5b;                   \
        FTR_ENTRY_OFFSET label##4b-label##5b;                   \
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
        .popsection;
 
 
Quoted 5 lines
Quoted 4 lines

I've pushed a branch with all your patches applied to:

https://github.com/linuxppc/linux/commits/next-test

This works for me. Thanks!

Great.

Quoted 7 lines
Quoted 4 lines

Are you able to give that a quick test? It builds clean with clang for me, but we must be using different versions of clang because my branch already builds clean for me even without your patches.

You may need to set LLVM_IAS=1 to get the behavior I'm seeing. That turns on clang's integrated assembler, which I think is disabled by default.

Quoted 8 lines

Yep that does it.

But then I get:
clang: error: unsupported argument '-mpower4' to option 'Wa,'
clang: error: unsupported argument '-many' to option 'Wa,'

So I guess I'm still missing something?

[Resent, because my previous email went out as non-plain text.]

I've seen that too. I'm not entirely sure what's causing it, but I'll look into it. I've got a backlog of things to work on still. :-) It's probably a clang issue. There's another one that came up having to do with the format of some PPC instructions. I have a clang fix on review for those.

Quoted 7 lines
Quoted 3 lines

Note that with clang's integrated assembler, arch/powerpc/boot/util.S fails to compile. Alan Modra mentioned that he sent you a patch to "modernize" the file so that clang can compile it.

Ah you're right he did, it didn't go to patchwork so I missed it. Have grabbed it now.

Thanks!

-bw

#20 lore raw

Re: [PATCH v3 3/3] powerpc/64s: feature: Work around inline asm issues

In reply to Michael Ellerman
Quoted 105 lines · Michael Ellerman
Quoted 1 line · Bill Wendling

On Mon, Nov 23, 2020 at 7:44 PM Michael Ellerman <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 3 lines · Bill Wendling
Quoted 1 line · Segher Boessenkool

On Mon, Nov 23, 2020 at 12:01:01PM -0800, Bill Wendling wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Segher Boessenkool
Quoted 3 lines
Quoted 1 line · Segher Boessenkool

"true" (as a result of a comparison) in as is -1, not 1.

Quoted 1 line · Bill Wendling

What Segher said. :-) Also, if you reverse the comparison,

you'll get

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/powerpc/include/asm/feature-fixups.h label##5: \

Quoted 8 lines
Quoted 1 line

a build error.

But that means your patch is the wrong way around?

arch/powerpc/include/asm/feature-fixups.h +1 -3
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       .org . - ((label##4b-label##3b) >

(label##2b-label##1b)); \

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It should be a + in that last line, not a -.

I said so in a follow up email.

Yeah, and that arrived a second after I pressed "send" :-)

Michael, I apologize for the churn with these patches. I believe the policy is to resend the match as "v4", correct?

Quoted 8 lines

Review

Quoted 8 lines
Quoted 3 lines

I ran tests with the change above. It compiled with no error. If I switch the labels around to ".org . + ((label##2b-label##1b) > (label##4b-label##3b))", then it fails as expected.

I wanted to retain the nicer error reporting for gcc builds, so I did it like this:

(quoted diff) +0 -0

b/arch/powerpc/include/asm/feature-fixups.h

Quoted 4 lines

arch/powerpc/include/asm/feature-fixups.h label##2:

Quoted 4 lines

index b0af97add751..c4ad33074df5 100644

arch/powerpc/include/asm/feature-fixups.h +0 -0
@@ -36,6 +36,24 @@ label##2:

\

Quoted 12 lines

arch/powerpc/include/asm/feature-fixups.h label##2: \

Quoted 12 lines
arch/powerpc/include/asm/feature-fixups.h +9 -0
        .align 2;                                       \
 label##3:
 
+
+#ifndef CONFIG_CC_IS_CLANG
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .ifgt (else_size) - (body_size);                        \
+       .error "Feature section else case larger than body";    \
+       .endif;
+#else
+/*
+ * If we use the ifgt syntax above, clang's assembler complains about

the

Quoted 1 line

arch/powerpc/include/asm/feature-fixups.h label##2: · line 48

Quoted 1 line
arch/powerpc/include/asm/feature-fixups.h +1 -0
+ * expression being non-absolute when the code appears in an inline

assembly

Quoted 2 lines

arch/powerpc/include/asm/feature-fixups.h label##2: · line 50

Quoted 2 lines
arch/powerpc/include/asm/feature-fixups.h +2 -0
+ * statement.
+ * As a workaround use an .org directive that has no effect if the

else case

Quoted 10 lines

arch/powerpc/include/asm/feature-fixups.h label##5:

Quoted 10 lines
arch/powerpc/include/asm/feature-fixups.h +6 -0
+ * instructions are smaller than the body, but fails otherwise.
+ */
+#define CHECK_ALT_SIZE(else_size, body_size)                   \
+       .org . + ((else_size) > (body_size));
+#endif
+
 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)          \
 label##4:                                                      \
        .popsection;                                            \
@@ -48,9 +66,7 @@ label##5:
         \
Quoted 11 lines
Quoted 11 lines
arch/powerpc/include/asm/feature-fixups.h +1 -3
        FTR_ENTRY_OFFSET label##2b-label##5b;                   \
        FTR_ENTRY_OFFSET label##3b-label##5b;                   \
        FTR_ENTRY_OFFSET label##4b-label##5b;                   \
-       .ifgt (label##4b- label##3b)-(label##2b- label##1b);    \
-       .error "Feature section else case larger than body";    \
-       .endif;                                                 \
+       CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
        .popsection;
 
 
Quoted 5 lines
Quoted 4 lines

I've pushed a branch with all your patches applied to:

https://github.com/linuxppc/linux/commits/next-test

This works for me. Thanks!

Great.

Quoted 7 lines
Quoted 4 lines

Are you able to give that a quick test? It builds clean with clang for me, but we must be using different versions of clang because my branch already builds clean for me even without your patches.

You may need to set LLVM_IAS=1 to get the behavior I'm seeing. That turns on clang's integrated assembler, which I think is disabled by default.

Quoted 8 lines

Yep that does it.

But then I get:
clang: error: unsupported argument '-mpower4' to option 'Wa,'
clang: error: unsupported argument '-many' to option 'Wa,'

So I guess I'm still missing something?

I've seen that too. I'm not entirely sure what's causing it, but I'll look into it. I've got a backlog of things to work on still. :-) It's probably a clang issue. There's another one that came up having to do with the format of some PPC instructions. I have a clang fix on review for those.

Quoted 7 lines

Note that with clang's integrated assembler, arch/powerpc/boot/util.S

Quoted 2 lines

fails to compile. Alan Modra mentioned that he sent you a patch to "modernize" the file so that clang can compile it.

Ah you're right he did, it didn't go to patchwork so I missed it. Have grabbed it now.

Thanks!
-bw

Quoted 1 line