exec_elf32.c (ed575be4685189d1095041d4bad3f5ca75c16cd4) exec_elf32.c (757686b11510174fffffec96b816204c8d659fba)
1/*
2 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 178 unchanged lines hidden (view full) ---

187
188int
189ELFNAMEEND(hide)(int fd, const char *fn)
190{
191 Elf_Ehdr ehdr;
192 Elf_Shdr *shdrp = NULL, *symtabshdr, *strtabshdr;
193 Elf_Sym *symtabp = NULL;
194 char *strtabp = NULL;
1/*
2 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 178 unchanged lines hidden (view full) ---

187
188int
189ELFNAMEEND(hide)(int fd, const char *fn)
190{
191 Elf_Ehdr ehdr;
192 Elf_Shdr *shdrp = NULL, *symtabshdr, *strtabshdr;
193 Elf_Sym *symtabp = NULL;
194 char *strtabp = NULL;
195 Elf_Word *symfwmap = NULL, *symrvmap = NULL, nsyms, nlocalsyms, ewi;
195 Elf_Size *symfwmap = NULL, *symrvmap = NULL, nsyms, nlocalsyms, ewi;
196 struct listelem *relalist = NULL, *rellist = NULL, *tmpl;
197 ssize_t shdrsize;
198 int rv, i, weird;
199 unsigned char data;
200
201 rv = 0;
202 if (xreadatoff(fd, &ehdr, 0, sizeof ehdr, fn) != sizeof ehdr)
203 goto bad;

--- 86 unchanged lines hidden (view full) ---

290 if (xreadatoff(fd, tmpl->mem, tmpl->file,
291 tmpl->size, fn) != tmpl->size)
292 goto bad;
293 }
294
295 /* Prepare data structures for symbol movement. */
296 nsyms = xewtoh(symtabshdr->sh_size) / xewtoh(symtabshdr->sh_entsize);
297 nlocalsyms = xe32toh(symtabshdr->sh_info);
196 struct listelem *relalist = NULL, *rellist = NULL, *tmpl;
197 ssize_t shdrsize;
198 int rv, i, weird;
199 unsigned char data;
200
201 rv = 0;
202 if (xreadatoff(fd, &ehdr, 0, sizeof ehdr, fn) != sizeof ehdr)
203 goto bad;

--- 86 unchanged lines hidden (view full) ---

290 if (xreadatoff(fd, tmpl->mem, tmpl->file,
291 tmpl->size, fn) != tmpl->size)
292 goto bad;
293 }
294
295 /* Prepare data structures for symbol movement. */
296 nsyms = xewtoh(symtabshdr->sh_size) / xewtoh(symtabshdr->sh_entsize);
297 nlocalsyms = xe32toh(symtabshdr->sh_info);
298 if ((symfwmap = xmalloc(nsyms * sizeof (Elf_Word), fn,
298 if ((symfwmap = xmalloc(nsyms * sizeof (Elf_Size), fn,
299 "symbol forward mapping table")) == NULL)
300 goto bad;
299 "symbol forward mapping table")) == NULL)
300 goto bad;
301 if ((symrvmap = xmalloc(nsyms * sizeof (Elf_Word), fn,
301 if ((symrvmap = xmalloc(nsyms * sizeof (Elf_Size), fn,
302 "symbol reverse mapping table")) == NULL)
303 goto bad;
304
305 /* init location -> symbol # table */
306 for (ewi = 0; ewi < nsyms; ewi++)
307 symrvmap[ewi] = ewi;
308
309 /* move symbols, making them local */
310 for (ewi = nlocalsyms; ewi < nsyms; ewi++) {
311 Elf_Sym *sp, symswap;
302 "symbol reverse mapping table")) == NULL)
303 goto bad;
304
305 /* init location -> symbol # table */
306 for (ewi = 0; ewi < nsyms; ewi++)
307 symrvmap[ewi] = ewi;
308
309 /* move symbols, making them local */
310 for (ewi = nlocalsyms; ewi < nsyms; ewi++) {
311 Elf_Sym *sp, symswap;
312 Elf_Word mapswap;
312 Elf_Size mapswap;
313
314 sp = &symtabp[ewi];
315
316 /* if it's on our keep list, don't move it */
317 if (in_keep_list(strtabp + xe32toh(sp->st_name)))
318 continue;
319
320 /* if it's an undefined symbol, keep it */

--- 105 unchanged lines hidden ---
313
314 sp = &symtabp[ewi];
315
316 /* if it's on our keep list, don't move it */
317 if (in_keep_list(strtabp + xe32toh(sp->st_name)))
318 continue;
319
320 /* if it's an undefined symbol, keep it */

--- 105 unchanged lines hidden ---