Skip to content

Commit f47462c

Browse files
bwendlingmpe
authored andcommitted
powerpc: Work around inline asm issues in alternate feature sections
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. Signed-off-by: Bill Wendling <[email protected]> [mpe: Put it in a macro and only do the workaround for clang] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 215fadf commit f47462c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ label##2: \
3636
.align 2; \
3737
label##3:
3838

39+
40+
#ifndef CONFIG_CC_IS_CLANG
41+
#define CHECK_ALT_SIZE(else_size, body_size) \
42+
.ifgt (else_size) - (body_size); \
43+
.error "Feature section else case larger than body"; \
44+
.endif;
45+
#else
46+
/*
47+
* If we use the ifgt syntax above, clang's assembler complains about the
48+
* expression being non-absolute when the code appears in an inline assembly
49+
* statement.
50+
* As a workaround use an .org directive that has no effect if the else case
51+
* instructions are smaller than the body, but fails otherwise.
52+
*/
53+
#define CHECK_ALT_SIZE(else_size, body_size) \
54+
.org . + ((else_size) > (body_size));
55+
#endif
56+
3957
#define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect) \
4058
label##4: \
4159
.popsection; \
@@ -48,9 +66,7 @@ label##5: \
4866
FTR_ENTRY_OFFSET label##2b-label##5b; \
4967
FTR_ENTRY_OFFSET label##3b-label##5b; \
5068
FTR_ENTRY_OFFSET label##4b-label##5b; \
51-
.ifgt (label##4b- label##3b)-(label##2b- label##1b); \
52-
.error "Feature section else case larger than body"; \
53-
.endif; \
69+
CHECK_ALT_SIZE((label##4b-label##3b), (label##2b-label##1b)); \
5470
.popsection;
5571

5672

0 commit comments

Comments
 (0)