From 7e502816f647fe0d4b00df3bffbd2e8409abe2ca Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Fri, 12 Mar 2021 22:01:46 -0800 Subject: [PATCH] [include][compiler.h] Fix INCBIN/INCFILE macros The compiler.h header defines two macros INCBIN and INCFILE that can be used to include binary files into C sources. This patch fixes a few issues with them: * The .align directive is equivalent to .p2align on some architectures (ARM/AArch64) and to .balign on others (x86). INCBIN previously used .align and now uses .balign for correct alignment. * .align 1 enforces a 2-byte alignment on ARM/AArch64, which caused the _end symbol for the binary to be off by 1 byte in some cases, which the macro previously accounted for (incorrectly). With the correct .balign directive the extra byte is never added, so the size is now correctly computed without the -1 addend. * INCBIN should end in a .previous directive to restore the previous section, since the macro starts with .section. Bug: 115420908 Change-Id: I2149e21d6f7157369a7b374a51af23933bff6b39 --- top/include/lk/compiler.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/top/include/lk/compiler.h b/top/include/lk/compiler.h index 1de70a39..b8884b77 100644 --- a/top/include/lk/compiler.h +++ b/top/include/lk/compiler.h @@ -40,12 +40,12 @@ #define __RESTRICT __restrict #define INCBIN(symname, sizename, filename, section) \ - __asm__ (".section " section "; .align 4; .globl "#symname); \ + __asm__ (".section " section "; .balign 4; .globl "#symname); \ __asm__ (""#symname ":\n.incbin \"" filename "\""); \ - __asm__ (".section " section "; .align 1;"); \ - __asm__ (""#symname "_end:"); \ - __asm__ (".section " section "; .align 4; .globl "#sizename); \ - __asm__ (""#sizename ": .long "#symname "_end - "#symname " - 1"); \ + __asm__ (".balign 1; "#symname "_end:"); \ + __asm__ (".balign 4; .globl "#sizename); \ + __asm__ (""#sizename ": .long "#symname "_end - "#symname); \ + __asm__ (".previous"); \ extern unsigned char symname[]; \ extern unsigned int sizename