summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/PrinterWriter.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Language/Elna/PrinterWriter.hs')
-rw-r--r--lib/Language/Elna/PrinterWriter.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Language/Elna/PrinterWriter.hs b/lib/Language/Elna/PrinterWriter.hs
index d0c1fe3..ff8b9aa 100644
--- a/lib/Language/Elna/PrinterWriter.hs
+++ b/lib/Language/Elna/PrinterWriter.hs
@@ -211,9 +211,17 @@ riscv32Elf code objectHandle = text
, st_name = fromIntegral $ ByteString.length names
, st_info = stInfo STB_GLOBAL STT_FUNC
}
+ printEntry = Elf32_Sym
+ { st_value = 0
+ , st_size = 0
+ , st_shndx = 0
+ , st_other = 0
+ , st_name = fromIntegral (ByteString.length names) + 7
+ , st_info = stInfo STB_GLOBAL STT_FUNC
+ }
liftIO $ ByteString.hPut objectHandle $ LazyByteString.toStrict encoded
- let newResult = ElfHeaderResult (names <> "_start\0")
- $ Vector.snoc entries newEntry
+ let newResult = ElfHeaderResult (names <> "_start\0printi\0")
+ $ Vector.snoc (Vector.snoc entries newEntry) printEntry
pure (newResult, size, updatedRelocations)
encodeInstruction (instructions, offset, relocations) instruction =
let unresolvedRelocation = case instruction of
@@ -227,6 +235,9 @@ riscv32Elf code objectHandle = text
| RiscV.Lower12S symbolName _ _ _ <- instructionType
-> Just -- R_RISCV_LO12_S
$ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 28
+ RiscV.CallInstruction symbolName
+ -> Just -- R_RISCV_CALL_PLT
+ $ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 19
RiscV.Instruction _ _ -> Nothing
encoded = ByteString.Builder.toLazyByteString
$ RiscV.instruction instruction