// a.c #include <stdio.h> int main() { puts("hello"); }
gcc -O2 -fdata-sections -c a.c && readelf -WS a.o | grep .rodata [ 4] .rodata.str1.1 PROGBITS 0000000000000000 000040 000006 01 AMS 0 0 1 gcc -O2 -fdata-sections -fno-merge-constants -c a.c && readelf -WS a.o | grep .rodata [ 4] .rodata PROGBITS 0000000000000000 000040 000006 00 A 0 0 1 clang -O2 -fdata-sections -c a.c && readelf -WS a.o | grep .rodata [ 4] .rodata.str1.1 PROGBITS 0000000000000000 00004f 000006 01 AMS 0 0 1 clang -O2 -fdata-sections -fno-merge-constants -c a.c && readelf -WS a.o | grep .rodata clang: warning: optimization flag '-fno-merge-constants' is not supported [-Wignored-optimization-argument] [ 4] .rodata.str1.1 PROGBITS 0000000000000000 00004f 000006 01 AMS 0 0 1
As you can see, clang (as of 10.0.0) does not support -f(no-)merge-constants. (clang supports -fmerge-all-constants but -fno-merge-constants vs -fmerge-constants is sufficient to cause the section name/flags(SHF_MERGE|SHF_STRINGS) difference).
commit e574997809bc67ab0c150af9c4b5e451091fb259 "build: Keep segmented sections separate until final link step." added -fno-merge-constants to avoid handling of .rodata.str1.1
In GCC, -O implies -fmerge-constants. If I delete -fno-merge-constants, scripts/checkrom.py will complain:
Error! Code does not end at 0x100000 (got 0xffd80)
It seems that we may need to add back some .rodata.str1.1 code for clang support.