Skip to content

Commit 9661796

Browse files
authored
Fix/aarch64 optimization relro (#7)
* Implemented improvements but real bug is not solved. * Add docker command for testing. * Add full warnings and improve code. * Improved bugs on osx.
1 parent ee9f1ce commit 9661796

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

plthook_osx.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ typedef struct {
188188
static int plthook_open_real(plthook_t **plthook_out, uint32_t image_idx, const struct mach_header *mh, const char *image_name);
189189
static unsigned int set_bind_addrs(data_t *data, unsigned int idx, uint32_t bind_off, uint32_t bind_size, char weak);
190190
static void set_bind_addr(data_t *d, unsigned int *idx, const char *sym_name, int seg_index, int seg_offset, int addend, char weak);
191-
static int read_chained_fixups(data_t *d, const struct mach_header *mh, const char *image_name);
191+
static int read_chained_fixups(data_t *d, const char *image_name);
192192
#ifdef PLTHOOK_DEBUG_FIXUPS
193193
static const char *segment_name_from_addr(data_t *d, size_t addr);
194194
static const char *section_name_from_addr(data_t *d, size_t addr);
@@ -332,9 +332,11 @@ static int plthook_open_real(plthook_t **plthook_out, uint32_t image_idx, const
332332
struct load_command *cmd;
333333
const struct dyld_info_command *dyld_info = NULL;
334334
unsigned int nbind;
335-
data_t data = {NULL,};
335+
data_t data;
336336
size_t size;
337-
int i;
337+
uint32_t i;
338+
339+
memset(&data, 0, sizeof(data_t));
338340

339341
data.linkedit_segment_idx = -1;
340342
data.slide = _dyld_get_image_vmaddr_slide(image_idx);
@@ -533,7 +535,7 @@ static int plthook_open_real(plthook_t **plthook_out, uint32_t image_idx, const
533535
return PLTHOOK_INVALID_FILE_FORMAT;
534536
}
535537
if (data.chained_fixups != NULL) {
536-
int rv = read_chained_fixups(&data, mh, image_name);
538+
int rv = read_chained_fixups(&data, image_name);
537539
if (rv != 0) {
538540
return rv;
539541
}
@@ -807,7 +809,7 @@ static int chained_fixups_iter_next(chained_fixups_iter_t *iter, chianed_fixups_
807809
return 0;
808810
}
809811

810-
static int read_chained_fixups(data_t *d, const struct mach_header *mh, const char *image_name)
812+
static int read_chained_fixups(data_t *d, const char *image_name)
811813
{
812814
const uint8_t *ptr = fileoff_to_vmaddr_in_segment(d, d->linkedit_segment_idx, d->chained_fixups->dataoff);
813815
const struct dyld_chained_fixups_header *header = (const struct dyld_chained_fixups_header *)ptr;
@@ -817,9 +819,11 @@ static int read_chained_fixups(data_t *d, const struct mach_header *mh, const ch
817819
size_t size;
818820
const struct dyld_chained_starts_in_image *starts = (const struct dyld_chained_starts_in_image *)(ptr + header->starts_offset);
819821
const struct dyld_chained_import *import = (const struct dyld_chained_import *)(ptr + header->imports_offset);
820-
chained_fixups_iter_t iter = {NULL, };
822+
chained_fixups_iter_t iter;
821823
chianed_fixups_entry_t entry;
822824

825+
memset(&iter, 0, sizeof(chained_fixups_iter_t));
826+
823827
rv = chained_fixups_iter_init(&iter, image_name, starts);
824828
if (rv != 0) {
825829
return rv;

test/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
UNAME_S := $(shell uname -s)
66

77
CFLAGS_SHARED = -shared -fPIC
8-
CFLAGS_WARNING = -Wall -Wpedantic -Wextra
8+
ifeq ($(findstring clang,$(CC)),clang)
9+
CFLAGS_WARNING = -Weverything -Wpedantic
10+
else
11+
CFLAGS_WARNING = -Wall -Wextra -Wpedantic
12+
endif
913
CFLAGS = $(CFLAGS_WARNING) $(EXTRA_CFLAGS) $(OPT_CFLAGS)
1014
LDFLAGS = $(EXTRA_LDFLAGS) $(OPT_LDFLAGS)
1115
EXEEXT =

test/testprog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static enum_test_data_t funcs_called_by_libtest[] = {
4040
#else
4141
{"strtod", 0},
4242
#endif
43-
{NULL, },
43+
{NULL, 0},
4444
};
4545

4646
static enum_test_data_t funcs_called_by_main[] = {
@@ -65,7 +65,7 @@ static enum_test_data_t funcs_called_by_main[] = {
6565
#else
6666
{"strtod_cdecl", 0},
6767
#endif
68-
{NULL, },
68+
{NULL, 0},
6969
};
7070

7171
#define STRTOD_STR_SIZE 30

0 commit comments

Comments
 (0)