diff options
author | Jerome Forissier <jerome.forissier@linaro.org> | 2018-11-12 15:36:42 +0100 |
---|---|---|
committer | Jérôme Forissier <jerome.forissier@linaro.org> | 2018-11-13 17:26:09 +0100 |
commit | fd118772593999c94e8aff13bd445ac3064f88ca (patch) | |
tree | 3286b2f10781bb1f026d54ece9f1ecaad0101534 /lib | |
parent | 01d6a9da27b50dac71b223e65411e8392cbf71cd (diff) |
core: force read-only flag on .rodata.* sections
This commit fixes a warning with GCC 8.2 that did not occur with GCC 6.2:
$ make out/arm-plat-vexpress/core/arch/arm/kernel/user_ta.o
CHK out/arm-plat-vexpress/conf.mk
CHK out/arm-plat-vexpress/include/generated/conf.h
CHK out/arm-plat-vexpress/core/include/generated/asm-defines.h
CC out/arm-plat-vexpress/core/arch/arm/kernel/user_ta.o
{standard input}: Assembler messages:
{standard input}:4087: Warning: setting incorrect section attributes for .rodata.__unpaged
The message is printed as the assembler processes this code fragment,
generated by the C compiler:
.section .rodata.__unpaged,"aw"
The older compiler (GCC 6.2) would generate instead:
.section .rodata.__unpaged,"a",%progbits
The problem with .rodata.__unpaged,"aw" is that the "w" (writeable) flag
is not consistent with the section name (.rodata.*), which by convention
is supposed to be read-only.
- The section name (".rodata.__unpaged") is given by our macro:
__rodata_unpaged.
- The "w" flag is added by GCC, not sure why exactly. One reason [1] is
when a relocatable binary is being generated and the structure contains
relocatable data. But, we are not explicitly asking for a relocatable
binary, so this might as well be a bug or counter-intuitive feature of
the compiler.
Anyway, to avoid the warning, we need to fix the section flags. The
section type (%progbits) is optional, it is deduced from the section name
by default. %progbits indicates that the section contains data (i.e., is
not empty).
Link: [1] https://gcc.gnu.org/ml/gcc/2004-05/msg01016.html
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU)
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960)
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutils/ext/include/compiler.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libutils/ext/include/compiler.h b/lib/libutils/ext/include/compiler.h index d1c6c97a..fdfe9f69 100644 --- a/lib/libutils/ext/include/compiler.h +++ b/lib/libutils/ext/include/compiler.h @@ -40,9 +40,17 @@ #define __section(x) __attribute__((section(x))) #define __data __section(".data") #define __bss __section(".bss") -#define __rodata __section(".rodata") -#define __rodata_unpaged __section(".rodata.__unpaged") -#define __early_ta __section(".rodata.early_ta") +/* + * Override sections flags/type generated by the C compiler to make sure they + * are: "a",%progbits (thus creating an allocatable, non-writeable, non- + * executable data section). + * The trailing '//' comments out the flags generated by the compiler. + * This avoids a harmless warning with GCC 8.x. + */ +#define __SECTION_FLAGS_RODATA ",\"a\",%progbits //" +#define __rodata __section(".rodata" __SECTION_FLAGS_RODATA) +#define __rodata_unpaged __section(".rodata.__unpaged" __SECTION_FLAGS_RODATA) +#define __early_ta __section(".rodata.early_ta" __SECTION_FLAGS_RODATA) #define __noprof __attribute__((no_instrument_function)) #define __compiler_bswap64(x) __builtin_bswap64((x)) |