/******************************************************* Function: ld_set_section_data *******************************************************/ void ld_set_section_data(void *pobj,int ndx) { bfd *abfd = (bfd *) pobj; Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); Elf_Internal_Shdr *p_shdr = i_shdrp[ndx]; size_t size = p_shdr->sh_size; char *buf; if (!size) return; buf = ((char *) bfd_malloc (size)); if (buf == NULL) { fprintf(stderr,"bfd_malloc failed in ld_set_section_data for %s\n",abfd->filename); exit(1); } if (!p_shdr->contents) { if (bfd_seek ( abfd, p_shdr->sh_offset, SEEK_SET) != 0) { fprintf(stderr,"bfd_seek failed in ld_set_section_data for %s\n",abfd->filename); exit(1); } if (bfd_read ( (PTR) buf, 1, size, abfd) != size) { fprintf(stderr,"Bfd_read failed in ld_set_section_data for %s\n",abfd->filename); exit(1); } } return; }
/******************************************************* Function: ld_get_section_info *******************************************************/ unsigned long ld_get_section_info(void *pobj, int sect_ndx) { const bfd *abfd = (bfd *) pobj; Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); return ((unsigned long)i_shdrp[sect_ndx]->sh_info); }
/******************************************************* Function: ld_get_section_base Return the raw address of the given section the pass1 phase. *******************************************************/ char * ld_get_section_base (void *pobj, int sect_ndx) { const bfd *abfd = (bfd *) pobj; Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); Elf_Internal_Shdr *p_shdr = i_shdrp[sect_ndx]; return (char *)abfd->usrdata+p_shdr->sh_offset; }
/******************************************************* Function: ld_get_section_name *******************************************************/ char * ld_get_section_name(void *pobj, int sect_ndx) { bfd *abfd = (bfd *) pobj; Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); Elf_Internal_Shdr *p_shdr = i_shdrp[sect_ndx]; char *tbl = bfd_elf_get_str_section(abfd, elf_elfheader (abfd)->e_shstrndx); return &tbl[p_shdr->sh_name]; }
/******************************************************* Function: ld_release_section_data *******************************************************/ void ld_release_section_data(void *pobj,int ndx) { const bfd *abfd = (bfd *) pobj; Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); Elf_Internal_Shdr *p_shdr = i_shdrp[ndx]; if (p_shdr->contents) { free(p_shdr->contents); p_shdr->contents = NULL; } }
/******************************************************* Function: get_command_line *******************************************************/ string * get_command_line(bfd *abfd, string in_path, string out_path, int *arg_count) { static const_string default_compilation_flags[] = DEFAULT_COMPILATION_FLAGS; int i; int argc = 0; string *old_argv; string *new_argv; Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd); for (i = 1; i < (int)ehdr->e_shnum; i++) { Elf_Internal_Shdr *p_shdr = elf_elfsections (abfd)[i]; if (p_shdr->sh_info == WT_COMP_FLAGS) { char *base_addr; int j; ELF_WORD *args; if (p_shdr->sh_size <= 1) continue; base_addr = (char *) p_shdr->contents; argc = (int)(*((ELF_WORD *) base_addr)); args = (ELF_WORD *) (base_addr + sizeof(ELF_WORD)); old_argv = (string *) ALLOCA (sizeof(string) * argc); MALLOC_ASSERT (old_argv); for (j = 0; j < argc; j++) { OBJ_ASSERT (args[j] < (ELF_WORD)p_shdr->sh_size, abfd, "invalid WT_COMP_FLAGS WHIRL section"); old_argv[j] = base_addr + args[j]; } break; } } if (argc == 0) { argc = DEFAULT_COMPILATION_ARGC; old_argv = default_compilation_flags; } new_argv = (string *) MALLOC ((argc + 6) * sizeof(string)); MALLOC_ASSERT (new_argv); for (i = 0; i < argc; i++) new_argv[i] = old_argv[i]; new_argv[argc++] = "-64"; new_argv[argc++] = in_path; new_argv[argc++] = "-o"; new_argv[argc++] = out_path; new_argv[argc++] = "-c"; new_argv[argc] = 0; *arg_count = argc; return new_argv; } /* get_command_line */