Skip to content

Commit d88904b

Browse files
author
whitequark
committedAug 8, 2015
libdyld: add const qualifiers.
1 parent cf3a9e0 commit d88904b

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed
 

Diff for: ‎software/include/dyld/dyld.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
struct dyld_info {
77
Elf32_Addr base;
8-
void *init;
8+
const void *init;
99
const char *strtab;
10-
Elf32_Sym *symtab;
10+
const Elf32_Sym *symtab;
1111
struct {
1212
Elf32_Word nbucket;
1313
Elf32_Word nchain;
14-
Elf32_Word *bucket;
15-
Elf32_Word *chain;
14+
const Elf32_Word *bucket;
15+
const Elf32_Word *chain;
1616
} hash;
1717
};
1818

1919
#ifdef __cplusplus
2020
extern "C" {
2121
#endif
2222

23-
int dyld_load(void *shlib, Elf32_Addr base,
23+
int dyld_load(const void *shlib, Elf32_Addr base,
2424
Elf32_Addr (*resolve_import)(const char *),
2525
struct dyld_info *info, const char **error_out);
2626
void *dyld_lookup(const char *symbol, struct dyld_info *info);

Diff for: ‎software/libdyld/dyld.c

+18-17
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include <string.h>
44
#include <dyld.h>
55

6-
static int fixup_rela(struct dyld_info *info, Elf32_Rela *rela,
6+
static int fixup_rela(struct dyld_info *info, const Elf32_Rela *rela,
77
Elf32_Addr (*resolve_import)(const char *),
88
const char **error_out)
99
{
10-
Elf32_Sym *sym = NULL;
10+
const Elf32_Sym *sym = NULL;
1111
if(ELF32_R_SYM(rela->r_info) != 0)
1212
sym = &info->symtab[ELF32_R_SYM(rela->r_info)];
1313
Elf32_Addr value;
@@ -49,11 +49,11 @@ static int fixup_rela(struct dyld_info *info, Elf32_Rela *rela,
4949
return 1;
5050
}
5151

52-
int dyld_load(void *shlib, Elf32_Addr base,
52+
int dyld_load(const void *shlib, Elf32_Addr base,
5353
Elf32_Addr (*resolve_import)(const char *),
5454
struct dyld_info *info, const char **error_out)
5555
{
56-
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)shlib;
56+
const Elf32_Ehdr *ehdr = (const Elf32_Ehdr *)shlib;
5757

5858
const unsigned char expected_ident[EI_NIDENT] = {
5959
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
@@ -75,14 +75,14 @@ int dyld_load(void *shlib, Elf32_Addr base,
7575
#error Unsupported architecture
7676
#endif
7777

78-
Elf32_Phdr *phdr = (Elf32_Phdr *)((intptr_t)shlib + ehdr->e_phoff);
79-
Elf32_Dyn *dyn = NULL;
78+
const Elf32_Phdr *phdr = (const Elf32_Phdr *)((intptr_t)shlib + ehdr->e_phoff);
79+
const Elf32_Dyn *dyn = NULL;
8080
for(int i = 0; i < ehdr->e_phnum; i++) {
8181
if(phdr[i].p_type == PT_DYNAMIC)
82-
dyn = (Elf32_Dyn *)((intptr_t)shlib + phdr[i].p_offset);
82+
dyn = (const Elf32_Dyn *)((intptr_t)shlib + phdr[i].p_offset);
8383

8484
memcpy((void*)(base + phdr[i].p_vaddr),
85-
(void*)((intptr_t)shlib + phdr[i].p_offset),
85+
(const void*)((intptr_t)shlib + phdr[i].p_offset),
8686
phdr[i].p_filesz);
8787
}
8888

@@ -91,23 +91,24 @@ int dyld_load(void *shlib, Elf32_Addr base,
9191
return 0;
9292
}
9393

94-
char *strtab = NULL;
95-
Elf32_Sym *symtab = NULL;
96-
Elf32_Rela *rela = NULL, *pltrel = NULL;
97-
Elf32_Word *hash = NULL, init = 0;
94+
const char *strtab = NULL;
95+
const Elf32_Sym *symtab = NULL;
96+
const Elf32_Rela *rela = NULL, *pltrel = NULL;
97+
const Elf32_Word *hash = NULL;
98+
Elf32_Word init = 0;
9899
size_t syment = sizeof(Elf32_Sym), relaent = sizeof(Elf32_Rela),
99100
relanum = 0, pltrelnum = 0;
100101
while(dyn->d_tag != DT_NULL) {
101102
switch(dyn->d_tag) {
102-
case DT_STRTAB: strtab = (char *)(base + dyn->d_un.d_ptr); break;
103-
case DT_SYMTAB: symtab = (Elf32_Sym *)(base + dyn->d_un.d_ptr); break;
103+
case DT_STRTAB: strtab = (const char *)(base + dyn->d_un.d_ptr); break;
104+
case DT_SYMTAB: symtab = (const Elf32_Sym *)(base + dyn->d_un.d_ptr); break;
104105
case DT_SYMENT: syment = dyn->d_un.d_val; break;
105-
case DT_RELA: rela = (Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
106+
case DT_RELA: rela = (const Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
106107
case DT_RELAENT: relaent = dyn->d_un.d_val; break;
107108
case DT_RELASZ: relanum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
108-
case DT_JMPREL: pltrel = (Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
109+
case DT_JMPREL: pltrel = (const Elf32_Rela *)(base + dyn->d_un.d_ptr); break;
109110
case DT_PLTRELSZ: pltrelnum = dyn->d_un.d_val / sizeof(Elf32_Rela); break;
110-
case DT_HASH: hash = (Elf32_Word *)(base + dyn->d_un.d_ptr); break;
111+
case DT_HASH: hash = (const Elf32_Word *)(base + dyn->d_un.d_ptr); break;
111112
case DT_INIT: init = dyn->d_un.d_val; break;
112113

113114
case DT_REL:

0 commit comments

Comments
 (0)
Please sign in to comment.