I am a compiler engineer currently working on a project to run Grub2 with Clang + LLVM instead of GCC. I wanted to reach out to inquire about the difference in behavior between LLVM and GCC when using mcmodel=large
. Here’s an example:
test.c:
const char *test(void){
return "xx";
}
Execution with GCC:
$ gcc -o test.o -c test.c -mcmodel=large
$ readelf -r test.o
Relocation section '.rela.text' at offset 0x200 contains 3 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000000 000200000113 R_AARCH64_ADR_PRE 0000000000000000 .text + 10
000000000004 000200000115 R_AARCH64_ADD_ABS 0000000000000000 .text + 10
000000000010 000500000101 R_AARCH64_ABS64 0000000000000000 .rodata + 0
Relocation section '.rela.eh_frame' at offset 0x248 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
00000000001c 000200000105 R_AARCH64_PREL32 0000000000000000 .text + 0
Execution with Clang:
$ clang -o test.o -c test.c -mcmodel=large
$ readelf -r test.o
Relocation section '.rela.text' at offset 0x1c0 contains 4 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000000 000700000108 R_AARCH64_MOVW_UA 0000000000000000 .rodata.str1.1 + 0
000000000004 00070000010a R_AARCH64_MOVW_UA 0000000000000000 .rodata.str1.1 + 0
000000000008 00070000010c R_AARCH64_MOVW_UA 0000000000000000 .rodata.str1.1 + 0
00000000000c 00070000010d R_AARCH64_MOVW_UA 0000000000000000 .rodata.str1.1 + 0
Relocation section '.rela.eh_frame' at offset 0x220 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
00000000001c 000600000104 R_AARCH64_PREL64 0000000000000000 .text + 0
Given this discrepancy, I would like to inquire about the reasons behind the difference in behavior between LLVM and GCC when it comes to supporting mcmodel=large
. Understanding the rationale behind this distinction would greatly contribute to our project’s development and help us make informed decisions regarding compiler selection for Grub2.
Thank you for your attention to this matter and for your valuable contributions to the LLVM compiler technology. I appreciate any insights you can provide regarding this topic.