static void checkblock(void *bp) { REQUIRES (bp!=NULL); REQUIRES ((size_t)(bp)%8 == 0); if ((size_t)bp % 8) printf("Error: %p is not doubleword aligned\n", bp); if (GET(HDRP(GET_LOC(bp))) != GET(FTRP(GET_LOC(bp)))) printf("Error: header does not match footer\n"); }
static void *get_pred(void *bp) { REQUIRES (bp!=NULL); REQUIRES ((size_t)(bp)%8 == 0); bp = (void*)((char*)(bp) + WSIZE); bp = GET_LOC(bp); ENSURES ( (size_t)(bp)%8 == 0); if ((long)bp == BASE) return NULL; else return bp; }
static void *get_succ(void *bp) { //printf ("root %p \n",(void*)root); //printf ("getting successor of %p\n",bp); REQUIRES (bp != NULL); REQUIRES ((size_t)(bp)%8 == 0); bp = GET_LOC(bp); //printf("succ = %p \n ",bp); if ( (long)bp == BASE) return NULL; else{ //rintf ("successor = %p",bp); return (bp); } }
static int build_file(Elf *src_elf, GElf_Ehdr *src_ehdr, Cmd_Info *cmd_info) { Elf_Scn *src_scn; Elf_Scn *dst_scn; int new_sh_name = 0; /* to hold the offset for the new */ /* section's name */ Elf *dst_elf = 0; Elf_Data *elf_data; Elf_Data *data; int64_t scn_no, x; size_t no_of_symbols = 0; section_info_table *info; unsigned int c = 0; int fdtmp; GElf_Shdr src_shdr; GElf_Shdr dst_shdr; GElf_Ehdr dst_ehdr; GElf_Off new_offset = 0, r; size_t shnum, shstrndx; if (elf_getshnum(src_elf, &shnum) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (elf_getshstrndx(src_elf, &shstrndx) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if ((fdtmp = open(elftmpfile, O_RDWR | O_TRUNC | O_CREAT, (mode_t)0666)) == -1) { error_message(OPEN_TEMP_ERROR, SYSTEM_ERROR, strerror(errno), prog, elftmpfile); return (FAILURE); } if ((dst_elf = elf_begin(fdtmp, ELF_C_WRITE, (Elf *) 0)) == NULL) { error_message(READ_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog, elftmpfile); (void) close(fdtmp); return (FAILURE); } if (gelf_newehdr(dst_elf, gelf_getclass(src_elf)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } /* initialize dst_ehdr */ (void) gelf_getehdr(dst_elf, &dst_ehdr); dst_ehdr = *src_ehdr; /* * flush the changes to the ehdr so the * ident array is filled in. */ (void) gelf_update_ehdr(dst_elf, &dst_ehdr); if (src_ehdr->e_phnum != 0) { (void) elf_flagelf(dst_elf, ELF_C_SET, ELF_F_LAYOUT); if (gelf_newphdr(dst_elf, src_ehdr->e_phnum) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } for (x = 0; x < src_ehdr->e_phnum; ++x) { GElf_Phdr dst; GElf_Phdr src; /* LINTED */ (void) gelf_getphdr(src_elf, (int)x, &src); /* LINTED */ (void) gelf_getphdr(dst_elf, (int)x, &dst); (void) memcpy(&dst, &src, sizeof (GElf_Phdr)); /* LINTED */ (void) gelf_update_phdr(dst_elf, (int)x, &dst); } x = location(dst_ehdr.e_phoff, 0, src_elf); if (x == AFTER) new_offset = (GElf_Off)src_ehdr->e_ehsize; } scn_no = 1; while ((src_scn = sec_table[scn_no].scn) != (Elf_Scn *) -1) { info = &sec_table[scn_no]; /* If section should be copied to new file NOW */ if ((info->secno != (GElf_Word)DELETED) && info->secno <= scn_no) { if ((dst_scn = elf_newscn(dst_elf)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } (void) gelf_getshdr(dst_scn, &dst_shdr); (void) gelf_getshdr(info->scn, &src_shdr); (void) memcpy(&dst_shdr, &src_shdr, sizeof (GElf_Shdr)); /* * Update link and info fields * The sh_link field may have special values so * check them first. */ if ((src_shdr.sh_link >= shnum) || (src_shdr.sh_link == 0)) dst_shdr.sh_link = src_shdr.sh_link; else if ((int)sec_table[src_shdr.sh_link].secno < 0) dst_shdr.sh_link = 0; else dst_shdr.sh_link = sec_table[src_shdr.sh_link].secno; if ((src_shdr.sh_type == SHT_REL) || (src_shdr.sh_type == SHT_RELA)) { if ((src_shdr.sh_info >= shnum) || ((int)sec_table[src_shdr. sh_info].secno < 0)) dst_shdr.sh_info = 0; else dst_shdr.sh_info = sec_table[src_shdr.sh_info].secno; } data = sec_table[scn_no].data; if ((elf_data = elf_newdata(dst_scn)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } *elf_data = *data; /* SHT_{DYNSYM, SYMTAB} might need some change */ if (((src_shdr.sh_type == SHT_SYMTAB) || (src_shdr.sh_type == SHT_DYNSYM)) && src_shdr.sh_entsize != 0 && (cmd_info->no_of_delete != 0 || cmd_info->no_of_nulled != 0)) { char *new_sym; no_of_symbols = src_shdr.sh_size / src_shdr.sh_entsize; new_sym = malloc(no_of_symbols * src_shdr.sh_entsize); if (new_sym == NULL) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } /* CSTYLED */ elf_data->d_buf = (void *) new_sym; for (c = 0; c < no_of_symbols; c++) { GElf_Sym csym; (void) gelf_getsym(data, c, &csym); if ((csym.st_shndx < SHN_LORESERVE) && (csym.st_shndx != SHN_UNDEF)) { section_info_table *i; i = &sec_table[csym.st_shndx]; if (((int)i->secno != DELETED) && ((int)i->secno != NULLED)) csym.st_shndx = i->secno; else { if (src_shdr.sh_type == SHT_SYMTAB) /* * The section which * this * symbol relates * to is removed. * There is no way to * specify this fact, * just change the shndx * to 1. */ csym.st_shndx = 1; else { /* * If this is in a * .dynsym, NULL it out. */ csym.st_shndx = 0; csym.st_name = 0; csym.st_value = 0; csym.st_size = 0; csym.st_info = 0; csym.st_other = 0; csym.st_shndx = 0; } } } (void) gelf_update_sym(elf_data, c, &csym); } } /* update SHT_SYMTAB_SHNDX */ if ((src_shdr.sh_type == SHT_SYMTAB_SHNDX) && (src_shdr.sh_entsize != 0) && ((cmd_info->no_of_delete != 0) || (cmd_info->no_of_nulled != 0))) { GElf_Word *oldshndx; GElf_Word *newshndx; uint_t entcnt; entcnt = src_shdr.sh_size / src_shdr.sh_entsize; oldshndx = data->d_buf; newshndx = malloc(entcnt * src_shdr.sh_entsize); if (newshndx == NULL) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } elf_data->d_buf = (void *)newshndx; for (c = 0; c < entcnt; c++) { if (oldshndx[c] != SHN_UNDEF) { section_info_table *i; i = &sec_table[oldshndx[c]]; if (((int)i->secno != DELETED) && ((int)i->secno != NULLED)) newshndx[c] = i->secno; else newshndx[c] = oldshndx[c]; } else newshndx[c] = oldshndx[c]; } } /* * If the section is to be updated, * do so. */ if (ISCANDIDATE(info->flags)) { if ((GET_LOC(info->flags) == PRIOR) && (((int)info->secno == NULLED) || ((int)info->secno == EXPANDED) || ((int)info->secno == SHRUNK))) { /* * The section is updated, * but the position is not too * good. Need to NULL this out. */ dst_shdr.sh_name = 0; dst_shdr.sh_type = SHT_PROGBITS; if ((int)info->secno != NULLED) { (cmd_info->no_of_moved)++; SET_MOVING(info->flags); } } else { /* * The section is positioned AFTER, * or there are no segments. * It is safe to update this section. */ data = sec_table[scn_no].mdata; *elf_data = *data; dst_shdr.sh_size = elf_data->d_size; } } /* add new section name to shstrtab? */ else if (!Sect_exists && (new_sec_string != NULL) && (scn_no == shstrndx) && (dst_shdr.sh_type == SHT_STRTAB) && ((src_ehdr->e_phnum == 0) || ((x = scn_location(dst_scn, dst_elf)) != IN) || (x != PRIOR))) { size_t sect_len; sect_len = strlen(SECT_NAME); if ((elf_data->d_buf = malloc((dst_shdr.sh_size + sect_len + 1))) == NULL) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } /* put original data plus new data in section */ (void) memcpy(elf_data->d_buf, data->d_buf, data->d_size); (void) memcpy(&((char *)elf_data->d_buf) [data->d_size], SECT_NAME, sect_len + 1); /* LINTED */ new_sh_name = (int)dst_shdr.sh_size; dst_shdr.sh_size += sect_len + 1; elf_data->d_size += sect_len + 1; } /* * Compute offsets. */ if (src_ehdr->e_phnum != 0) { /* * Compute section offset. */ if (off_table[scn_no] == 0) { if (dst_shdr.sh_addralign != 0) { r = new_offset % dst_shdr.sh_addralign; if (r) new_offset += dst_shdr.sh_addralign - r; } dst_shdr.sh_offset = new_offset; elf_data->d_off = 0; } else { if (nobits_table[scn_no] == 0) new_offset = off_table[scn_no]; } if (nobits_table[scn_no] == 0) new_offset += dst_shdr.sh_size; } } (void) gelf_update_shdr(dst_scn, &dst_shdr); /* flush changes */ scn_no++; } /* * This is the real new section. */ if (!Sect_exists && new_sec_string != NULL) { size_t string_size; string_size = strlen(new_sec_string) + 1; if ((dst_scn = elf_newscn(dst_elf)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } (void) gelf_getshdr(dst_scn, &dst_shdr); dst_shdr.sh_name = new_sh_name; dst_shdr.sh_type = SHT_PROGBITS; dst_shdr.sh_flags = 0; dst_shdr.sh_addr = 0; if (src_ehdr->e_phnum != NULL) dst_shdr.sh_offset = new_offset; else dst_shdr.sh_offset = 0; dst_shdr.sh_size = string_size + 1; dst_shdr.sh_link = 0; dst_shdr.sh_info = 0; dst_shdr.sh_addralign = 1; dst_shdr.sh_entsize = 0; (void) gelf_update_shdr(dst_scn, &dst_shdr); /* flush changes */ if ((elf_data = elf_newdata(dst_scn)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } elf_data->d_size = string_size + 1; if ((elf_data->d_buf = (char *) calloc(1, string_size + 1)) == NULL) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } (void) memcpy(&((char *)elf_data->d_buf)[1], new_sec_string, string_size); elf_data->d_align = 1; new_offset += string_size + 1; } /* * If there are sections which needed to be moved, * then do it here. */ if (cmd_info->no_of_moved != 0) { int cnt; info = &sec_table[0]; for (cnt = 0; cnt < shnum; cnt++, info++) { if ((GET_MOVING(info->flags)) == 0) continue; if ((src_scn = elf_getscn(src_elf, info->osecno)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (gelf_getshdr(src_scn, &src_shdr) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if ((dst_scn = elf_newscn(dst_elf)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (gelf_getshdr(dst_scn, &dst_shdr) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } dst_shdr = src_shdr; data = info->mdata; dst_shdr.sh_offset = new_offset; /* UPDATE fields */ dst_shdr.sh_size = data->d_size; if ((shnum >= src_shdr.sh_link) || (src_shdr.sh_link == 0)) dst_shdr.sh_link = src_shdr.sh_link; else dst_shdr.sh_link = sec_table[src_shdr.sh_link].osecno; if ((shnum >= src_shdr.sh_info) || (src_shdr.sh_info == 0)) dst_shdr.sh_info = src_shdr.sh_info; else dst_shdr.sh_info = sec_table[src_shdr.sh_info].osecno; (void) gelf_update_shdr(dst_scn, &dst_shdr); if ((elf_data = elf_newdata(dst_scn)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } (void) memcpy(elf_data, data, sizeof (Elf_Data)); new_offset += data->d_size; } } /* * In the event that the position of the sting table has changed, * as a result of deleted sections, update the ehdr->e_shstrndx. */ if ((shstrndx > 0) && (shnum > 0) && (sec_table[shstrndx].secno < shnum)) { if (sec_table[shstrndx].secno < SHN_LORESERVE) { dst_ehdr.e_shstrndx = sec_table[dst_ehdr.e_shstrndx].secno; } else { Elf_Scn *_scn; GElf_Shdr shdr0; /* * If shstrndx requires 'Extended ELF Sections' * then it is stored in shdr[0].sh_link */ dst_ehdr.e_shstrndx = SHN_XINDEX; if ((_scn = elf_getscn(dst_elf, 0)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } (void) gelf_getshdr(_scn, &shdr0); shdr0.sh_link = sec_table[shstrndx].secno; (void) gelf_update_shdr(_scn, &shdr0); } } if (src_ehdr->e_phnum != 0) { size_t align = gelf_fsize(dst_elf, ELF_T_ADDR, 1, EV_CURRENT); /* UPDATE location of program header table */ if (location(dst_ehdr.e_phoff, 0, dst_elf) == AFTER) { r = new_offset % align; if (r) new_offset += align - r; dst_ehdr.e_phoff = new_offset; new_offset += dst_ehdr.e_phnum * dst_ehdr.e_phentsize; } /* UPDATE location of section header table */ if ((location(dst_ehdr.e_shoff, 0, src_elf) == AFTER) || ((location(dst_ehdr.e_shoff, 0, src_elf) == PRIOR) && (!Sect_exists && new_sec_string != NULL))) { r = new_offset % align; if (r) new_offset += align - r; dst_ehdr.e_shoff = new_offset; } free(b_e_seg_table); /* * The NOTE segment is the one segment whos * sections might get moved by mcs processing. * Make sure that the NOTE segments offset points * to the .note section. */ if ((notesegndx != -1) && (notesctndx != -1) && (sec_table[notesctndx].secno)) { Elf_Scn * notescn; GElf_Shdr nshdr; notescn = elf_getscn(dst_elf, sec_table[notesctndx].secno); (void) gelf_getshdr(notescn, &nshdr); if (gelf_getclass(dst_elf) == ELFCLASS32) { Elf32_Phdr * ph = elf32_getphdr(dst_elf) + notesegndx; /* LINTED */ ph->p_offset = (Elf32_Off)nshdr.sh_offset; } else { Elf64_Phdr * ph = elf64_getphdr(dst_elf) + notesegndx; ph->p_offset = (Elf64_Off)nshdr.sh_offset; } } } /* copy ehdr changes back into real ehdr */ (void) gelf_update_ehdr(dst_elf, &dst_ehdr); if (elf_update(dst_elf, ELF_C_WRITE) < 0) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } (void) elf_end(dst_elf); (void) close(fdtmp); return (SUCCESS); }
static int traverse_file(Elf *elf, GElf_Ehdr * ehdr, char *cur_file, Cmd_Info *cmd_info) { Elf_Scn * scn; Elf_Scn * temp_scn; Elf_Data * data; GElf_Shdr * shdr; char *temp_name; section_info_table * sinfo; GElf_Xword x; int ret = 0, SYM = 0; /* used by strip command */ int phnum = ehdr->e_phnum; unsigned int i, scn_index; size_t shstrndx, shnum; Sect_exists = 0; if (elf_getshnum(elf, &shnum) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } if (elf_getshstrndx(elf, &shstrndx) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } scn = 0; scn_index = 1; sinfo = &sec_table[scn_index]; while ((scn = elf_nextscn(elf, scn)) != 0) { char *name; shdr = &(sinfo->shdr); if (gelf_getshdr(scn, shdr) == NULL) { error_message(NO_SECT_TABLE_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog, cur_file); return (FAILURE); } else { name = elf_strptr(elf, shstrndx, (size_t)shdr->sh_name); if (name == NULL) name = "_@@@###"; } sinfo->scn = scn; sinfo->secno = scn_index; sinfo->osecno = scn_index; SET_ACTION(sinfo->flags, ACT_NOP); sinfo->name = name; if (ehdr->e_phnum == 0) SET_LOC(sinfo->flags, NOSEG); else SET_LOC(sinfo->flags, scn_location(scn, elf)); if (shdr->sh_type == SHT_GROUP) { if (list_appendc(&cmd_info->sh_groups, sinfo) == 0) { error_message(MALLOC_ERROR, PLAIN_ERROR, (char *)0, prog); mcs_exit(FAILURE); } } /* * If the target section is pointed by a section * holding relocation infomation, then the * pointing section would be useless if the * target section is removed. */ if ((shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA) && (shdr->sh_info != SHN_UNDEF && (temp_scn = elf_getscn(elf, shdr->sh_info)) != 0)) { GElf_Shdr tmp_shdr; if (gelf_getshdr(temp_scn, &tmp_shdr) != NULL) { temp_name = elf_strptr(elf, shstrndx, (size_t)tmp_shdr.sh_name); sinfo->rel_name = temp_name; sinfo->rel_scn_index = shdr->sh_info; if (phnum == 0) sinfo->rel_loc = NOSEG; else sinfo->rel_loc = scn_location(temp_scn, elf); } } data = 0; if ((data = elf_getdata(scn, data)) == NULL) { error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog); return (FAILURE); } sinfo->data = data; /* * Check if this section is a candidate for * action to be processes. */ if (sectcmp(name) == 0) { SET_CANDIDATE(sinfo->flags); /* * This flag just shows that there was a * candidate. */ Sect_exists++; } /* * Any of the following section types should * also be removed (if possible) if invoked via * the 'strip' command. */ if (CHK_OPT(cmd_info, I_AM_STRIP) && ((shdr->sh_type == SHT_SUNW_DEBUG) || (shdr->sh_type == SHT_SUNW_DEBUGSTR))) { SET_CANDIDATE(sinfo->flags); Sect_exists++; } /* * Zap this file ? */ if ((cmd_info->flags & zFLAG) && (shdr->sh_type == SHT_PROGBITS)) { SET_CANDIDATE(sinfo->flags); Sect_exists++; } x = GET_LOC(sinfo->flags); /* * Remeber the note sections index so that we can * reset the NOTE segments offset to point to it. * * It may have been assigned a new location in the * resulting output elf image. */ if (shdr->sh_type == SHT_NOTE) notesctndx = scn_index; if (x == IN || x == PRIOR) off_table[scn_index] = shdr->sh_offset; if (shdr->sh_type == SHT_NOBITS) nobits_table[scn_index] = 1; /* * If this section satisfies the condition, * apply the actions specified. */ if (ISCANDIDATE(sinfo->flags)) { ret += apply_action(sinfo, cur_file, cmd_info); } /* * If I am strip command, determine if symtab can go or not. */ if (CHK_OPT(cmd_info, I_AM_STRIP) && (CHK_OPT(cmd_info, xFLAG) == 0) && (CHK_OPT(cmd_info, lFLAG) == 0)) { if (shdr->sh_type == SHT_SYMTAB && GET_LOC(sinfo->flags) == AFTER) { SYM = scn_index; } } scn_index++; sinfo++; } sinfo->scn = (Elf_Scn *) -1; /* * If there were any errors traversing the file, * just return error. */ if (ret != 0) return (FAILURE); /* * Remove symbol table if possible */ if (CHK_OPT(cmd_info, I_AM_STRIP) && SYM != 0) { GElf_Shdr tmp_shdr; (void) gelf_getshdr(sec_table[SYM].scn, &tmp_shdr); sec_table[SYM].secno = (GElf_Word)DELETED; ++(cmd_info->no_of_nulled); if (Sect_exists == 0) ++Sect_exists; SET_ACTION(sec_table[SYM].flags, ACT_DELETE); off_table[SYM] = 0; /* * Can I remove section header * string table ? */ if ((tmp_shdr.sh_link < shnum) && (tmp_shdr.sh_link != SHN_UNDEF) && (tmp_shdr.sh_link != shstrndx) && (GET_LOC(sec_table[tmp_shdr.sh_link].flags) == AFTER)) { sec_table[tmp_shdr.sh_link].secno = (GElf_Word)DELETED; ++(cmd_info->no_of_nulled); if (Sect_exists == 0) ++Sect_exists; SET_ACTION(sec_table[tmp_shdr.sh_link].flags,\ ACT_DELETE); off_table[tmp_shdr.sh_link] = 0; } } /* * If I only printed the contents, then * just report so. */ if (CHK_OPT(cmd_info, pFLAG) && !CHK_OPT(cmd_info, MIGHT_CHG)) return (DONT_BUILD); /* don't bother creating a new file */ /* since the file has not changed */ /* * I might need to add a new section. Check it. */ if (Sect_exists == 0 && CHK_OPT(cmd_info, aFLAG)) { int act = 0; new_sec_string = calloc(1, cmd_info->str_size + 1); if (new_sec_string == NULL) return (FAILURE); for (act = 0; act < actmax; act++) { if (Action[act].a_action == ACT_APPEND) { (void) strcat(new_sec_string, Action[act].a_string); (void) strcat(new_sec_string, "\n"); cmd_info->no_of_append = 1; } } } /* * If I did not append any new sections, and I did not * modify/delete any sections, then just report so. */ if ((Sect_exists == 0 && cmd_info->no_of_append == 0) || !CHK_OPT(cmd_info, MIGHT_CHG)) return (DONT_BUILD); /* * Found at least one section which was processed. * Deleted or Appended or Compressed. */ if (Sect_exists) { /* * First, handle the deleted sections. */ if (cmd_info->no_of_delete != 0 || cmd_info->no_of_nulled != 0) { int acc = 0; int rel_idx; /* * Handle relocation/target * sections. */ sinfo = &(sec_table[0]); for (i = 1; i < shnum; i++) { sinfo++; rel_idx = sinfo->rel_scn_index; if (rel_idx == 0) continue; /* * If I am removed, then remove my * target section. */ if (((sinfo->secno == (GElf_Word)DELETED) || (sinfo->secno == (GElf_Word)NULLED)) && sinfo->rel_loc != IN) { if (GET_LOC(sec_table[rel_idx].flags) == PRIOR) sec_table[rel_idx].secno = (GElf_Word)NULLED; else sec_table[rel_idx].secno = (GElf_Word)DELETED; SET_ACTION(sec_table[rel_idx].flags,\ ACT_DELETE); } /* * I am not removed. Check if my target is * removed or nulled. If so, let me try to * remove my self. */ if (((sec_table[rel_idx].secno == (GElf_Word)DELETED) || (sec_table[rel_idx].secno == (GElf_Word)NULLED)) && (GET_LOC(sinfo->flags) != IN)) { if (GET_LOC(sinfo->flags) == PRIOR) sinfo->secno = (GElf_Word)NULLED; else sinfo->secno = (GElf_Word)DELETED; SET_ACTION(sinfo->flags,\ ACT_DELETE); } } /* * Now, take care of DELETED sections */ sinfo = &(sec_table[1]); for (i = 1; i < shnum; i++) { shdr = &(sinfo->shdr); if (sinfo->secno == (GElf_Word)DELETED) { acc++; /* * The SHT_GROUP section which this section * is a member may be able to be removed. * See post_process(). */ if (shdr->sh_flags & SHF_GROUP) cmd_info->flags |= SHF_GROUP_DEL; } else { /* * The data buffer of SHT_GROUP this section * is a member needs to be updated. * See post_process(). */ sinfo->secno -= acc; if ((shdr->sh_flags & SHF_GROUP) && (acc != 0)) cmd_info->flags |= SHF_GROUP_MOVE; } sinfo++; } } } /* * I know that the file has been modified. * A new file need to be created. */ return (SUCCESS); }
void check_coalescing (void *bp) { if ( !GET_ALLOC(HDRP(GET_LOC(bp))) && !GET_ALLOC(HDRP(NEXT_BLKP(GET_LOC(bp))))) printf ("Blocks not coalesced properly"); }
void check_in_correct_bucket(void *bp, int bucket) { int offset = get_offset( GET_SIZE(HDRP(GET_LOC(bp)))); if (offset != bucket) printf("Block is in the wrong bucket! \n"); }