Previously, .reloc unconditionally errored on RISCV64 — only ARM64 had permission to use R_AARCH64_CALL26. Now supports common RISCV64 relocations: R_RISCV_CALL, CALL_PLT, BRANCH, JAL, PCREL_HI20, PCREL_LO12_I/S, 32_PCREL, 32, 64. Restructured to use string-to-reloc-type mapping, shared across all targets.
Unified · Split
| @@ -1014,17 +1014,41 @@ static void asm_parse_directive(TCCState *s1, int global) · 1013 unmodified lines | ||
| 1014 | 1014 | case TOK_ASMDIR_reloc: |
| 1015 | 1015 | { |
| 1016 | 1016 | ExprValue e; |
| 1017 | + const char *reloc_name; | |
| 1018 | + int reloc_type = -1; | |
| 1017 | 1019 | |
| 1018 | 1020 | next(); |
| 1019 | 1021 | asm_expr(s1, &e); |
| 1020 | 1022 | skip(','); |
| 1023 | + reloc_name = get_tok_str(tok, NULL); | |
| 1021 | 1024 | #if defined(TCC_TARGET_ARM64) |
| 1022 | − if (strcmp(get_tok_str(tok, NULL), "R_AARCH64_CALL26")) | |
| 1025 | + if (!strcmp(reloc_name, "R_AARCH64_CALL26")) | |
| 1026 | + reloc_type = R_AARCH64_CALL26; | |
| 1027 | +#elif defined(TCC_TARGET_RISCV64) | |
| 1028 | + if (!strcmp(reloc_name, "R_RISCV_CALL") || !strcmp(reloc_name, "R_RISCV_CALL_PLT")) | |
| 1029 | + reloc_type = R_RISCV_CALL; | |
| 1030 | + else if (!strcmp(reloc_name, "R_RISCV_BRANCH")) | |
| 1031 | + reloc_type = R_RISCV_BRANCH; | |
| 1032 | + else if (!strcmp(reloc_name, "R_RISCV_JAL")) | |
| 1033 | + reloc_type = R_RISCV_JAL; | |
| 1034 | + else if (!strcmp(reloc_name, "R_RISCV_PCREL_HI20")) | |
| 1035 | + reloc_type = R_RISCV_PCREL_HI20; | |
| 1036 | + else if (!strcmp(reloc_name, "R_RISCV_PCREL_LO12_I")) | |
| 1037 | + reloc_type = R_RISCV_PCREL_LO12_I; | |
| 1038 | + else if (!strcmp(reloc_name, "R_RISCV_PCREL_LO12_S")) | |
| 1039 | + reloc_type = R_RISCV_PCREL_LO12_S; | |
| 1040 | + else if (!strcmp(reloc_name, "R_RISCV_32_PCREL")) | |
| 1041 | + reloc_type = R_RISCV_32_PCREL; | |
| 1042 | + else if (!strcmp(reloc_name, "R_RISCV_32")) | |
| 1043 | + reloc_type = R_RISCV_32; | |
| 1044 | + else if (!strcmp(reloc_name, "R_RISCV_64")) | |
| 1045 | + reloc_type = R_RISCV_64; | |
| 1023 | 1046 | #endif |
| 1024 | − tcc_error("unimp: reloc '%s' unknown", get_tok_str(tok, NULL)); | |
| 1047 | + if (reloc_type < 0) | |
| 1048 | + tcc_error("unimp: reloc '%s' unknown", reloc_name); | |
| 1025 | 1049 | next(); |
| 1026 | 1050 | skip(','); |
| 1027 | − greloca(cur_text_section, get_asm_sym(tok, NULL), e.v, R_AARCH64_CALL26, 0); | |
| 1051 | + greloca(cur_text_section, get_asm_sym(tok, NULL), e.v, reloc_type, 0); | |
| 1028 | 1052 | next(); |
| 1029 | 1053 | } |
| 1030 | 1054 | break; |