Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: Don't define ALIGN and ENTRY when preprocessing linker scripts.

Adding a reference to <linux/linkage.h> to x86's <asm/cache.h> causes
the x86 linker script to have syntax errors, because the ALIGN and
ENTRY keywords get redefined to the assembly implementations of those.
One could fix this by adjusting the include structure, but I think any
solution based on that approach would be fragile.

Currently, it is impossible when writing a header to do something
different for assembly files and linker scripts, even though there are
clearly cases where one wants them to define macros differently for
the two (ENTRY being an excellent example).
So I think the right solution here is to introduce a new preprocessor
definition, called LINKER_SCRIPT that is set along with __ASSEMBLY__
for linker scripts, and to use that to not define ALIGN and ENTRY in
linker scripts.
I suspect we'll find other uses for this mechanism in
the future.

Signed-off-by: Tim Abbott <tabbott@ksplice.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

authored by

Tim Abbott and committed by
Sam Ravnborg
42f29a25 51b563fc

+3 -1
+2
include/linux/linkage.h
··· 57 57 58 58 #ifdef __ASSEMBLY__ 59 59 60 + #ifndef LINKER_SCRIPT 60 61 #define ALIGN __ALIGN 61 62 #define ALIGN_STR __ALIGN_STR 62 63 ··· 67 66 ALIGN; \ 68 67 name: 69 68 #endif 69 + #endif /* LINKER_SCRIPT */ 70 70 71 71 #ifndef WEAK 72 72 #define WEAK(name) \
+1 -1
scripts/Makefile.build
··· 271 271 # --------------------------------------------------------------------------- 272 272 quiet_cmd_cpp_lds_S = LDS $@ 273 273 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ 274 - -D__ASSEMBLY__ -o $@ $< 274 + -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< 275 275 276 276 $(obj)/%.lds: $(src)/%.lds.S FORCE 277 277 $(call if_changed_dep,cpp_lds_S)