Skip to content

Commit

Permalink
Improved libification.
Browse files Browse the repository at this point in the history
  • Loading branch information
endrazine committed Feb 4, 2023
1 parent 060f06a commit 8254480
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/wcc/wcc.c
Expand Up @@ -616,7 +616,8 @@ int rd_symbols(ctx_t * ctx)
if (storage_needed < 0) {
bfd_perror("warning: bfd_get_dynamic_symtab_upper_bound");
ret = 0;
goto out;
// goto out;
exit(EXIT_FAILURE);
}
if (storage_needed == 0) {
fprintf(stderr, "warning: no symbols\n");
Expand Down Expand Up @@ -1671,6 +1672,15 @@ int fixup_text(ctx_t * ctx)
s->s_elf->sh_size = newsz;
// extend data
s->data = realloc(s->data, newsz);
if(!s->data){
printf(" ERROR: realloc() %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (ctx->opt_debug) {
printf("newsize:%x s->len:%x\n",newsz,s->len);
}

// pad
memset(s->data + s->len, 0x00, newsz - s->len);
s->s_elf->sh_offset = orig_sz;
Expand Down
11 changes: 9 additions & 2 deletions src/wld/wld.c
Expand Up @@ -127,7 +127,8 @@ int mk_lib(char *name)
dyn->d_tag = DT_NULL;
dyn->d_un.d_val = -1;
break;
case DT_FLAGS_1: // Remove PIE flag if present
case DT_FLAGS_1: // Remove DF_1_NOOPEN and DF_1_PIE flags if present
dyn->d_un.d_val = dyn->d_un.d_val & ~DF_1_NOOPEN;
dyn->d_un.d_val = dyn->d_un.d_val & ~DF_1_PIE;
break;
default:
Expand All @@ -137,7 +138,13 @@ int mk_lib(char *name)
}
break;
}
}

// Find .gnu.version section and wipe it clear
if(shdr[i].sh_type == SHT_GNU_versym){
memset(map + shdr[i].sh_offset, 0x00, shdr[i].sh_size);
}

}

munmap(map, sb.st_size);
close(fd);
Expand Down

0 comments on commit 8254480

Please sign in to comment.