From 09810abe18c73788ff08e0b130bb168eab4e7bc0 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sun, 23 Feb 2020 17:13:15 +0100 Subject: [PATCH] as: assemble: create sections for relocations --- erlang/apps/as/src/assemble.erl | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/erlang/apps/as/src/assemble.erl b/erlang/apps/as/src/assemble.erl index e296aef..8e2544f 100644 --- a/erlang/apps/as/src/assemble.erl +++ b/erlang/apps/as/src/assemble.erl @@ -95,10 +95,29 @@ stmts(Section = #section{name = Name, data = {stmts, Stmts}}, Tunit0) -> , st_name = 0 , st_shndx = 0 }, - Tunit = tunit:put_symbol(Tunit0, SectionSymbol), - case stmts_image(lists:reverse(Stmts), Tunit, Name) of - {ok, {Image, _Relocs = []}} -> - {ok, tunit:put_section(Tunit, Section#section{data = {image, Image}})}; + Tunit1 = tunit:put_symbol(Tunit0, SectionSymbol), + case stmts_image(lists:reverse(Stmts), Tunit1, Name) of + {ok, {Image, Relocs}} -> + Tunit = tunit:put_section(Tunit1, Section#section{data = {image, Image}}), + case Relocs of + [] -> {ok, Tunit}; + _ -> + RelocationSection = + #section{ name = ".rela" ++ Name + , data = {relocs, Name, Relocs} + , dot = ?ELF36_RELA_SIZEOF * length(Relocs) + , shndx = 0 + , sh_name = 0 + , sh_type = ?SHT_RELA + , sh_offset = 0 + , sh_flags = ?SHF_INFO_LINK + , sh_link = ?SHN_UNDEF % assigned during output + , sh_info = ?SHN_UNDEF % assigned during output + , sh_addralign = 4 + , sh_entsize = ?ELF36_RELA_SIZEOF + }, + {ok, tunit:put_section(Tunit, RelocationSection)} + end; {error, _Reason} = Error -> Error end.