History

tccasm: extend .reloc directive for RISCV64 relocation types

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.

Meng Zhuo committed 6 months ago

Commit 2a33dae1 parent 3257afa1 file · +27 −3Browse files

Unified · Split

tccasm.c+27−3
@@ -1014,17 +1014,41 @@ static void asm_parse_directive(TCCState *s1, int global) · 1013 unmodified lines
10141014 case TOK_ASMDIR_reloc:
10151015 {
10161016 ExprValue e;
1017+ const char *reloc_name;
1018+ int reloc_type = -1;
10171019
10181020 next();
10191021 asm_expr(s1, &e);
10201022 skip(',');
1023+ reloc_name = get_tok_str(tok, NULL);
10211024 #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;
10231046 #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);
10251049 next();
10261050 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);
10281052 next();
10291053 }
10301054 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t