Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Apr 13, 2023
1 parent 81745ac commit 43021ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/libasr/codegen/x86_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,9 @@ void set_data_segment(X86Assembler &a, Elf64_Phdr* p_text_seg, Elf64_Phdr* p) {
p->align = 0x1000;
}

template <typename T>
void append_bytes(Allocator &al, T src, Vec<uint8_t> &des) {
char *byteArray = (char *)&src;
for (size_t i = 0; i < sizeof(src); i++) {
des.push_back(al, byteArray[i]);
void append_bytes(Allocator &al, Vec<uint8_t>& src, Vec<uint8_t> &des) {
for (size_t i = 0; i < src.size(); i++) {
des.push_back(al, src[i]);
}
}

Expand Down Expand Up @@ -450,16 +448,18 @@ Vec<uint8_t> create_elf64_x86_binary(Allocator &al, X86Assembler &a) {

const int PROGRAM_HEADER_SIZE = binary.size();

e->entry = a.get_defined_symbol("_start").value + PROGRAM_HEADER_SIZE;

p_program->filesz = PROGRAM_HEADER_SIZE;
p_program->memsz = p_program->filesz;

p_text_seg->offset = p_program->offset + p_program->filesz;
p_text_seg->vaddr = a.origin() + p_text_seg->offset;
p_text_seg->paddr = a.origin() + p_text_seg->offset;
p_text_seg->vaddr = a.origin() + p_text_seg->offset + PROGRAM_HEADER_SIZE;
p_text_seg->paddr = p_text_seg->vaddr;

p_data_seg->offset = p_text_seg->offset + p_text_seg->filesz;
p_data_seg->vaddr = a.origin() + p_data_seg->offset;
p_data_seg->paddr = a.origin() + p_data_seg->offset;
p_data_seg->vaddr = a.origin() + p_data_seg->offset + PROGRAM_HEADER_SIZE;
p_data_seg->paddr = p_data_seg->vaddr;

append_bytes(al, a.get_machine_code(), binary);
return binary;
Expand Down
5 changes: 2 additions & 3 deletions src/libasr/codegen/x86_assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class X86Assembler {
public:
X86Assembler(Allocator &al, bool bits64) : m_al{al} {
m_code.reserve(m_al, 1024*128);
m_origin = 0x08049000;
m_origin = 0x08048000;
#ifdef LFORTRAN_ASM_PRINT
if (bits64) {
m_asm_code = "BITS 64\n";
Expand Down Expand Up @@ -1542,8 +1542,7 @@ void emit_print(X86Assembler &a, const std::string &msg_label,
void emit_print_int(X86Assembler &a, const std::string &name);
void emit_print_float(X86Assembler &a, const std::string &name);

template <typename T>
void append_bytes(Allocator &al, T src, Vec<uint8_t> &des);
void append_bytes(Allocator &al, Vec<uint8_t>& src, Vec<uint8_t> &des);
void align_by_byte(Allocator &al, Vec<uint8_t> &code, uint64_t alignment);
Vec<uint8_t> create_elf64_x86_binary(Allocator &al, X86Assembler &a);

Expand Down

0 comments on commit 43021ba

Please sign in to comment.