Commit 0283b077 authored by luxufan's avatar luxufan
Browse files

reapply de872382 "[JITLink] Add anonymous symbols in LinkGraph..."

with fixes

This reapply `de872382`, which was
reverted in `fdb65785`

Add `# REQUIRES: asserts` in test file `anonymous_symbol.s` to disable
this test for non-debug build
parent 93deac2e
......@@ -79,6 +79,12 @@ enum EdgeKind_riscv : Edge::Kind {
/// Fixup <- (Target - Fixup + Addend)
R_RISCV_CALL,
/// 32 bits PC relative relocation
///
/// Fixup expression:
/// Fixup <- (Target - Fixup + Addend)
R_RISCV_32_PCREL,
/// PC relative GOT offset
///
/// Fixup expression:
......@@ -162,12 +168,6 @@ enum EdgeKind_riscv : Edge::Kind {
/// Fixup expression:
/// Fixup <- (Target + Addend)
R_RISCV_SET32,
/// Local label assignment
///
/// Fixup expression:
/// Fixup <- (Target - Fixup + Addend)
R_RISCV_32_PCREL,
};
/// Returns a string name for the given riscv edge. For debugging purposes
......
......@@ -441,11 +441,15 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
<< "\"\n";
});
// Model the section symbols as anonymous symbol.
// In RISCV, temporary symbols (Used to generate dwarf, eh_frame
// sections...) will appear in object code's symbol table, and LLVM does
// not use names on these temporary symbols (RISCV gnu toolchain uses
// names on these temporary symbols). If the symbol is unnamed, add an
// anonymous symbol.
auto &GSym =
Sym.getType() == ELF::STT_SECTION
? G->addAnonymousSymbol(*B, Sym.getValue(), Sym.st_size, false,
false)
Name->empty()
? G->addAnonymousSymbol(*B, Sym.getValue(), Sym.st_size,
false, false)
: G->addDefinedSymbol(*B, Sym.getValue(), *Name, Sym.st_size, L,
S, Sym.getType() == ELF::STT_FUNC, false);
setGraphSymbol(SymIndex, GSym);
......
......@@ -38,6 +38,8 @@ const char *getEdgeKindName(Edge::Kind K) {
return "R_RISCV_PCREL_LO12_S";
case R_RISCV_CALL:
return "R_RISCV_CALL";
case R_RISCV_32_PCREL:
return "R_RISCV_32_PCREL";
case R_RISCV_ADD64:
return "R_RISCV_ADD64";
case R_RISCV_ADD32:
......@@ -62,8 +64,6 @@ const char *getEdgeKindName(Edge::Kind K) {
return "R_RISCV_SET16";
case R_RISCV_SET32:
return "R_RISCV_SET32";
case R_RISCV_32_PCREL:
return "R_RISCV_32_PCREL";
}
return getGenericEdgeKindName(K);
}
......
# REQUIRES: asserts
# RUN: llvm-mc -triple=riscv64 -filetype=obj -o %t %s
# RUN: llvm-jitlink -debug-only=jitlink -noexec %t 2>&1 | FileCheck %s
#
# Because of the exist of cfi directive, sections like eh_frame section will be emitted
# in llvm's object code emission phase. Anonymous symbols will also be emitted to indicate
# the section start and section end. So that by relocating these symbol, the section length
# can be calculated.
#
# CHECK: Creating defined graph symbol for ELF symbol ""
# CHECK: Creating defined graph symbol for ELF symbol ""
.text
.globl main
.p2align 2
.type main,@function
main:
.cfi_startproc
ret
.Lfunc_end0:
.size main, .Lfunc_end0-main
.cfi_endproc
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment