Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 88b41f3

Browse files
committed
Changes to deploy on linux and linux section finding for 64-bit (should have been part of the last commit).
1 parent afbf07b commit 88b41f3

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

engine/src/deploy_linux.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,23 @@ struct MCLinuxELF32Traits
398398
typedef Elf32_Ehdr Ehdr;
399399
typedef Elf32_Shdr Shdr;
400400
typedef Elf32_Phdr Phdr;
401+
402+
inline static uint32_t round(uint32_t x)
403+
{
404+
return (x + 3) & ~3;
405+
}
401406
};
402407

403408
struct MCLinuxELF64Traits
404409
{
405410
typedef Elf64_Ehdr Ehdr;
406411
typedef Elf64_Shdr Shdr;
407412
typedef Elf64_Phdr Phdr;
413+
414+
inline static uint32_t round(uint32_t x)
415+
{
416+
return (x + 7) & ~7;
417+
}
408418
};
409419

410420
////////////////////////////////////////////////////////////////////////////////
@@ -761,7 +771,10 @@ Exec_stat MCDeployToELF(const MCDeployParameters& p_params, bool p_is_android)
761771
{
762772
t_success = MCDeployWritePayload(p_params, false, t_output, t_output_offset, t_payload_size);
763773
if (t_success)
774+
{
775+
t_payload_size = T::round(t_payload_size);
764776
t_output_offset += t_payload_size;
777+
}
765778
}
766779

767780
// Write out the project info struct
@@ -773,7 +786,10 @@ Exec_stat MCDeployToELF(const MCDeployParameters& p_params, bool p_is_android)
773786
t_project_offset = t_output_offset;
774787
t_success = MCDeployWriteProject(p_params, false, t_output, t_output_offset, t_project_size);
775788
if (t_success)
789+
{
790+
t_project_size = T::round(t_project_size);
776791
t_output_offset += t_project_size;
792+
}
777793
}
778794

779795
// Next use the project size to compute the updated header values we need.
@@ -820,10 +836,10 @@ Exec_stat MCDeployToELF(const MCDeployParameters& p_params, bool p_is_android)
820836

821837
//
822838

823-
t_section_table_size = t_header . e_shnum * sizeof(Elf32_Shdr);
839+
t_section_table_size = t_header . e_shnum * sizeof(typename T::Shdr);
824840
t_section_table_offset = t_header . e_shoff;
825841

826-
t_segment_table_size = t_header . e_phnum * sizeof(Elf32_Phdr);
842+
t_segment_table_size = t_header . e_phnum * sizeof(typename T::Phdr);
827843
t_segment_table_offset = t_header . e_phoff;
828844

829845
//

engine/src/mode_installer.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,19 @@ static void *MCExecutableFindSection(const char *p_name)
18741874
#elif defined(_LINUX)
18751875
#include <elf.h>
18761876

1877+
// MW-2013-05-03: [[ Linux64 ]] Make sure we use the correct structs for section
1878+
// searching.
1879+
1880+
#ifdef __LP64__
1881+
typedef Elf64_Ehdr Elf_Ehdr;
1882+
typedef Elf64_Shdr Elf_Shdr;
1883+
typedef Elf64_Phdr Elf_Phdr;
1884+
#else
1885+
typedef Elf32_Ehdr Elf_Ehdr;
1886+
typedef Elf32_Shdr Elf_Shdr;
1887+
typedef Elf32_Phdr Elf_Phdr;
1888+
#endif
1889+
18771890
static void *MCExecutableFindSection(const char *p_name)
18781891
{
18791892
bool t_success;
@@ -1891,22 +1904,22 @@ static void *MCExecutableFindSection(const char *p_name)
18911904
}
18921905

18931906
// Load the header
1894-
Elf32_Ehdr t_header;
1907+
Elf_Ehdr t_header;
18951908
if (t_success)
1896-
if (fread(&t_header, sizeof(Elf32_Ehdr), 1, t_exe) != 1)
1909+
if (fread(&t_header, sizeof(Elf_Ehdr), 1, t_exe) != 1)
18971910
t_success = false;
18981911

18991912
// Allocate memory for the section table
1900-
Elf32_Shdr *t_sections;
1913+
Elf_Shdr *t_sections;
19011914
t_sections = nil;
19021915
if (t_success)
1903-
t_success = MCMemoryAllocate(sizeof(Elf32_Shdr) * t_header . e_shnum, t_sections);
1916+
t_success = MCMemoryAllocate(sizeof(Elf_Shdr) * t_header . e_shnum, t_sections);
19041917

19051918
// Now read in the sections
19061919
for(uint32_t i = 0; i < t_header . e_shnum && t_success; i++)
19071920
{
19081921
if (fseek(t_exe, t_header . e_shoff + i * t_header . e_shentsize, SEEK_SET) != 0 ||
1909-
fread(&t_sections[i], sizeof(Elf32_Shdr), 1, t_exe) != 1)
1922+
fread(&t_sections[i], sizeof(Elf_Shdr), 1, t_exe) != 1)
19101923
t_success = false;
19111924
}
19121925

0 commit comments

Comments
 (0)