* elfcode.h (elf_swap_shdr_in): Use rawdata, not bfd_section.

Clear contents field.
	(bfd_section_from_shdr): In SHT_STRTAB case, check bfd_section,
	not rawdata.  Don't set rawdata if e_shstrndx.  Use bfd_section
	rather than rawdata in commented out code.  In SHT_REL[A] case,
	don't bother to check elf_section_data of section returned by
	section_from_elf_index.
	(elf_fake_sections): Set bfd_section, not rawdata.  Don't set
	size.
	(elf_map_symbols): Don't set elf_num_section_syms.  Don't create
	section symbols that already exist.
	(assign_file_position_for_section): Use bfd_section, not rawdata.
	(section_from_elf_index): Just check bfd_section field.
	(elf_section_from_bfd_section): Likewise.
	(elf_debug_section): Don't print rawdata, contents, or size.
	(elf_link_add_object_symbols): Don't error out if
	section_from_elf_index returns NULL.
	(elf_bfd_final_link): Check return value from
	section_from_elf_index against NULL, not bfd_is_abs_section.
	(elf_link_input_bfd): Don't check section_from_elf_index return
	value.
	* libelf.h (struct elf_obj_tdata): Remove num_section_syms field.
	(elf_num_section_syms): Don't define.
	* elf.c (elf_get_str_section): Store section contents in contents
	field rather than rawdata field.
	(elf_string_from_elf_section): Likewise.
	(_bfd_elf_make_section_from_shdr): Store BFD section pointer in
	bfd_section field rather than rawdata field.
	* elf32-hppa.c (elf32_hppa_read_symext_info): Use bfd_section
	rather than rawdata.
	(elf32_hppa_size_stubs): Likewise.
	* elf32-mips.c (mips_elf_final_write_processing): Use bfd_section
	rathern than rawdata.
	(mips_elf_section_from_shdr): Likewise.
	(mips_elf_section_processing): Likewise.
	(mips_elf_section_from_bfd_section): Remove rawdata check.
This commit is contained in:
Ian Lance Taylor 1994-10-17 18:27:40 +00:00
parent 5e643795a3
commit 24f13b0331
5 changed files with 2202 additions and 2178 deletions

View File

@ -1,5 +1,42 @@
Mon Oct 17 11:38:16 1994 Ian Lance Taylor <ian@sanguine.cygnus.com>
* elfcode.h (elf_swap_shdr_in): Use rawdata, not bfd_section.
Clear contents field.
(bfd_section_from_shdr): In SHT_STRTAB case, check bfd_section,
not rawdata. Don't set rawdata if e_shstrndx. Use bfd_section
rather than rawdata in commented out code. In SHT_REL[A] case,
don't bother to check elf_section_data of section returned by
section_from_elf_index.
(elf_fake_sections): Set bfd_section, not rawdata. Don't set
size.
(elf_map_symbols): Don't set elf_num_section_syms. Don't create
section symbols that already exist.
(assign_file_position_for_section): Use bfd_section, not rawdata.
(section_from_elf_index): Just check bfd_section field.
(elf_section_from_bfd_section): Likewise.
(elf_debug_section): Don't print rawdata, contents, or size.
(elf_link_add_object_symbols): Don't error out if
section_from_elf_index returns NULL.
(elf_bfd_final_link): Check return value from
section_from_elf_index against NULL, not bfd_is_abs_section.
(elf_link_input_bfd): Don't check section_from_elf_index return
value.
* libelf.h (struct elf_obj_tdata): Remove num_section_syms field.
(elf_num_section_syms): Don't define.
* elf.c (elf_get_str_section): Store section contents in contents
field rather than rawdata field.
(elf_string_from_elf_section): Likewise.
(_bfd_elf_make_section_from_shdr): Store BFD section pointer in
bfd_section field rather than rawdata field.
* elf32-hppa.c (elf32_hppa_read_symext_info): Use bfd_section
rather than rawdata.
(elf32_hppa_size_stubs): Likewise.
* elf32-mips.c (mips_elf_final_write_processing): Use bfd_section
rathern than rawdata.
(mips_elf_section_from_shdr): Likewise.
(mips_elf_section_processing): Likewise.
(mips_elf_section_from_bfd_section): Remove rawdata check.
* srec.c (pass_over): Set the start address for S7, S8 or S9.
Fri Oct 14 19:15:46 1994 Ken Raeburn <raeburn@cujo.cygnus.com>

File diff suppressed because it is too large Load Diff

View File

@ -71,7 +71,8 @@ static void mips_info_to_howto_rel
PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *));
static boolean mips_elf_object_p PARAMS ((bfd *));
static void mips_elf_final_write_processing PARAMS ((bfd *));
static void mips_elf_final_write_processing
PARAMS ((bfd *, boolean));
static boolean mips_elf_section_from_shdr
PARAMS ((bfd *, Elf32_Internal_Shdr *, char *));
static boolean mips_elf_fake_sections
@ -95,7 +96,7 @@ static void mips_elf_relocate_hi16
bfd_vma));
static boolean mips_elf_relocate_section
PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
Elf_Internal_Rela *, Elf_Internal_Sym *, asection **, char *));
static boolean mips_elf_add_symbol_hook
PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
const char **, flagword *, asection **, bfd_vma *));
@ -362,7 +363,7 @@ mips_elf_hi16_reloc (abfd,
abort ();
ret = bfd_reloc_ok;
if (symbol->section == &bfd_und_section
if (bfd_is_und_section (symbol->section)
&& output_bfd == (bfd *) NULL)
ret = bfd_reloc_undefined;
@ -548,7 +549,7 @@ mips_elf_gprel16_reloc (abfd,
output_bfd = symbol->section->output_section->owner;
}
if (symbol->section == &bfd_und_section
if (bfd_is_und_section (symbol->section)
&& relocateable == false)
return bfd_reloc_undefined;
@ -839,9 +840,11 @@ mips_elf_object_p (abfd)
file. This gets the MIPS architecture right based on the machine
number. */
/*ARGSUSED*/
static void
mips_elf_final_write_processing (abfd)
mips_elf_final_write_processing (abfd, linker)
bfd *abfd;
boolean linker;
{
unsigned long val;
unsigned int i;
@ -878,8 +881,8 @@ mips_elf_final_write_processing (abfd)
const char *name;
asection *sec;
BFD_ASSERT ((*hdrpp)->rawdata != NULL);
name = ((asection *) (*hdrpp)->rawdata)->name;
BFD_ASSERT ((*hdrpp)->bfd_section != NULL);
name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section);
BFD_ASSERT (name != NULL
&& strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0);
sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1);
@ -944,7 +947,7 @@ mips_elf_section_from_shdr (abfd, hdr, name)
if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
return false;
newsect = (asection *) hdr->rawdata;
newsect = hdr->bfd_section;
if (hdr->sh_type == SHT_MIPS_DEBUG)
{
@ -1042,8 +1045,6 @@ mips_elf_section_from_bfd_section (abfd, hdr, sec, retval)
*retval = SHN_MIPS_SCOMMON;
return true;
}
if ((asection *) hdr->rawdata == sec)
return true;
return false;
}
@ -1073,9 +1074,9 @@ mips_elf_section_processing (abfd, hdr)
return false;
}
if (hdr->rawdata != NULL)
if (hdr->bfd_section != NULL)
{
const char *name = ((asection *) hdr->rawdata)->name;
const char *name = bfd_get_section_name (abfd, hdr->bfd_section);
if (strcmp (name, ".sdata") == 0)
{
@ -1173,7 +1174,7 @@ mips_elf_symbol_processing (abfd, asym)
break;
case SHN_MIPS_SUNDEFINED:
asym->section = &bfd_und_section;
asym->section = bfd_und_section_ptr;
break;
}
}
@ -1409,7 +1410,7 @@ mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
break;
case SHN_MIPS_SUNDEFINED:
*secp = &bfd_und_section;
*secp = bfd_und_section_ptr;
break;
}
@ -2150,7 +2151,8 @@ mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend)
static boolean
mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
contents, relocs, local_syms, local_sections)
contents, relocs, local_syms, local_sections,
output_names)
bfd *output_bfd;
struct bfd_link_info *info;
bfd *input_bfd;
@ -2159,6 +2161,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
Elf_Internal_Rela *relocs;
Elf_Internal_Sym *local_syms;
asection **local_sections;
char *output_names;
{
Elf_Internal_Shdr *symtab_hdr;
size_t locsymcount;
@ -2372,9 +2375,7 @@ mips_elf_relocate_section (output_bfd, info, input_bfd, input_section,
name = h->root.root.string;
else
{
name = elf_string_from_elf_section (input_bfd,
symtab_hdr->sh_link,
sym->st_name);
name = output_names + sym->st_name;
if (name == NULL)
return false;
if (*name == '\0')

View File

@ -300,8 +300,8 @@ elf_swap_shdr_in (abfd, src, dst)
dst->sh_info = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_info);
dst->sh_addralign = get_word (abfd, (bfd_byte *) src->sh_addralign);
dst->sh_entsize = get_word (abfd, (bfd_byte *) src->sh_entsize);
/* we haven't done any processing on it yet, so... */
dst->rawdata = (void *) 0;
dst->bfd_section = NULL;
dst->contents = NULL;
}
/* Translate an ELF section header table entry in internal format into an
@ -575,13 +575,12 @@ bfd_section_from_shdr (abfd, shindex)
return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
case SHT_STRTAB: /* A string table */
if (hdr->rawdata != NULL)
if (hdr->bfd_section != NULL)
return true;
if (ehdr->e_shstrndx == shindex)
{
elf_tdata (abfd)->shstrtab_hdr = *hdr;
elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr;
hdr->rawdata = (PTR) & elf_tdata (abfd)->shstrtab_hdr;
return true;
}
{
@ -613,10 +612,10 @@ bfd_section_from_shdr (abfd, shindex)
#if 0 /* Not handling other string tables specially right now. */
hdr2 = elf_elfsections (abfd)[i]; /* in case it moved */
/* We have a strtab for some random other section. */
newsect = (asection *) hdr2->rawdata;
newsect = (asection *) hdr2->bfd_section;
if (!newsect)
break;
hdr->rawdata = (PTR) newsect;
hdr->bfd_section = newsect;
hdr2 = &elf_section_data (newsect)->str_hdr;
*hdr2 = *hdr;
elf_elfsections (abfd)[shindex] = hdr2;
@ -663,8 +662,7 @@ bfd_section_from_shdr (abfd, shindex)
if (! bfd_section_from_shdr (abfd, hdr->sh_info))
return false;
target_sect = section_from_elf_index (abfd, hdr->sh_info);
if (target_sect == NULL
|| elf_section_data (target_sect) == NULL)
if (target_sect == NULL)
return false;
hdr2 = &elf_section_data (target_sect)->rel_hdr;
@ -1188,9 +1186,8 @@ elf_fake_sections (abfd, asect, ignore)
this_hdr->sh_addralign = 1 << asect->alignment_power;
this_hdr->sh_entsize = 0;
this_hdr->rawdata = (PTR) asect;
this_hdr->bfd_section = asect;
this_hdr->contents = NULL;
this_hdr->size = 0;
/* FIXME: This should not be based on section names. */
if (strcmp (asect->name, ".dynstr") == 0)
@ -1279,7 +1276,6 @@ elf_fake_sections (abfd, asect, ignore)
rela_hdr->sh_addr = 0;
rela_hdr->sh_size = 0;
rela_hdr->sh_offset = 0;
rela_hdr->size = 0;
}
}
@ -1520,7 +1516,6 @@ elf_map_symbols (abfd)
}
max_index++;
elf_num_section_syms (abfd) = max_index;
sect_syms = (asymbol **) bfd_zalloc (abfd, max_index * sizeof (asymbol *));
elf_section_syms (abfd) = sect_syms;
@ -1530,18 +1525,40 @@ elf_map_symbols (abfd)
return false;
}
for (idx = 0; idx < symcount; idx++)
{
if ((syms[idx]->flags & BSF_SECTION_SYM) != 0)
{
asection *sec;
sec = syms[idx]->section;
if (! bfd_is_abs_section (sec))
{
if (sec->owner != abfd)
{
sec = sec->output_section;
BFD_ASSERT (sec->owner == abfd);
}
sect_syms[sec->index] = syms[idx];
}
}
}
for (asect = abfd->sections; asect; asect = asect->next)
{
asymbol *sym = bfd_make_empty_symbol (abfd);
if (!sym)
{
bfd_set_error (bfd_error_no_memory);
return false;
}
asymbol *sym;
if (sect_syms[asect->index] != NULL)
continue;
sym = bfd_make_empty_symbol (abfd);
if (sym == NULL)
return false;
sym->the_bfd = abfd;
sym->name = asect->name;
sym->value = asect->vma;
sym->flags = BSF_SECTION_SYM;
/* Set the flags to 0 to indicate that this one was newly added. */
sym->flags = 0;
sym->section = asect;
sect_syms[asect->index] = sym;
num_sections++;
@ -1554,15 +1571,15 @@ elf_map_symbols (abfd)
if (num_sections)
{
#if 0 /* @@ I just deleted bfd_realloc, because it's broken and too hard to
fix. I'm leaving this code here as a reminder to look at this more
carefully later and see if we can avoid wasting memory. */
if (syms)
syms = (asymbol **) bfd_realloc (abfd, syms,
{
asymbol **osyms = syms;
syms = (asymbol **) bfd_alloc (abfd,
((symcount + num_sections + 1)
* sizeof (asymbol *)));
memcpy (syms, osyms, symcount * sizeof (asymbol *));
}
else
#endif
syms = (asymbol **) bfd_alloc (abfd,
(num_sections + 1) * sizeof (asymbol *));
if (!syms)
@ -1573,8 +1590,12 @@ elf_map_symbols (abfd)
for (asect = abfd->sections; asect; asect = asect->next)
{
if (sect_syms[asect->index])
syms[symcount++] = sect_syms[asect->index];
if (sect_syms[asect->index] != NULL
&& sect_syms[asect->index]->flags == 0)
{
sect_syms[asect->index]->flags = BSF_SECTION_SYM;
syms[symcount++] = sect_syms[asect->index];
}
}
syms[symcount] = (asymbol *) 0;
@ -1699,8 +1720,8 @@ assign_file_position_for_section (i_shdrp, offset, align)
offset = BFD_ALIGN (offset, al);
}
i_shdrp->sh_offset = offset;
if (i_shdrp->rawdata != NULL)
((asection *) i_shdrp->rawdata)->filepos = offset;
if (i_shdrp->bfd_section != NULL)
i_shdrp->bfd_section->filepos = offset;
if (i_shdrp->sh_type != SHT_NOBITS)
offset += i_shdrp->sh_size;
return offset;
@ -2395,7 +2416,6 @@ swap_out_syms (abfd)
symstrtab_hdr->sh_link = 0;
symstrtab_hdr->sh_info = 0;
symstrtab_hdr->sh_addralign = 1;
symstrtab_hdr->size = 0;
}
return true;
@ -2524,52 +2544,18 @@ NAME(bfd_elf,write_object_contents) (abfd)
return write_shdrs_and_ehdr (abfd);
}
/* Given an index of a section, retrieve a pointer to it. Note
that for our purposes, sections are indexed by {1, 2, ...} with
0 being an illegal index. */
/* In the original, each ELF section went into exactly one BFD
section. This doesn't really make sense, so we need a real mapping.
The mapping has to hide in the Elf_Internal_Shdr since asection
doesn't have anything like a tdata field... */
/* Given an ELF section number, retrieve the corresponding BFD
section. */
static asection *
section_from_elf_index (abfd, index)
bfd *abfd;
unsigned int index;
{
/* @@ Is bfd_com_section_ptr really correct in all the places it could
be returned from this routine? */
if (index == SHN_ABS)
return bfd_com_section_ptr; /* not abs? */
if (index == SHN_COMMON)
return bfd_com_section_ptr;
BFD_ASSERT (index > 0 && index < SHN_LORESERVE);
if (index >= elf_elfheader (abfd)->e_shnum)
return NULL;
{
Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[index];
switch (hdr->sh_type)
{
/* ELF sections that map to BFD sections */
case SHT_PROGBITS:
case SHT_NOBITS:
case SHT_HASH:
case SHT_DYNAMIC:
if (hdr->rawdata == NULL)
{
if (! bfd_section_from_shdr (abfd, index))
return NULL;
}
return (struct sec *) hdr->rawdata;
default:
return bfd_abs_section_ptr;
}
}
return elf_elfsections (abfd)[index]->bfd_section;
}
/* given a section, search the header to find them... */
@ -2578,6 +2564,7 @@ elf_section_from_bfd_section (abfd, asect)
bfd *abfd;
struct sec *asect;
{
struct elf_backend_data *bed = get_elf_backend_data (abfd);
Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
int index;
Elf_Internal_Shdr *hdr;
@ -2599,56 +2586,20 @@ elf_section_from_bfd_section (abfd, asect)
for (index = 0; index < maxindex; index++)
{
hdr = i_shdrp[index];
switch (hdr->sh_type)
if (hdr->bfd_section == asect)
return index;
if (bed->elf_backend_section_from_bfd_section)
{
/* ELF sections that map to BFD sections */
case SHT_PROGBITS:
case SHT_NOBITS:
case SHT_NOTE:
case SHT_HASH:
case SHT_DYNAMIC:
case SHT_DYNSYM:
case SHT_SYMTAB:
if (hdr->rawdata)
{
if (((struct sec *) (hdr->rawdata)) == asect)
return index;
}
break;
int retval;
case SHT_REL:
case SHT_RELA:
/* We sometimes map a reloc section to a BFD section. */
if (hdr->sh_link != elf_onesymtab (abfd)
&& (asection *) hdr->rawdata == asect)
return index;
break;
case SHT_STRTAB:
/* We map most string tables to BFD sections. */
if (index != elf_elfheader (abfd)->e_shstrndx
&& index != elf_onesymtab (abfd)
&& (asection *) hdr->rawdata == asect)
return index;
/* FALL THROUGH */
default:
{
struct elf_backend_data *bed = get_elf_backend_data (abfd);
if (bed->elf_backend_section_from_bfd_section)
{
int retval;
retval = index;
if ((*bed->elf_backend_section_from_bfd_section)
(abfd, hdr, asect, &retval))
return retval;
}
}
break;
retval = index;
if ((*bed->elf_backend_section_from_bfd_section)
(abfd, hdr, asect, &retval))
return retval;
}
}
return -1;
}
@ -3073,9 +3024,6 @@ elf_debug_section (str, num, hdr)
(long) hdr->sh_addralign);
fprintf (stderr, "sh_entsize = %ld\n",
(long) hdr->sh_entsize);
fprintf (stderr, "rawdata = 0x%.8lx\n", (long) hdr->rawdata);
fprintf (stderr, "contents = 0x%.8lx\n", (long) hdr->contents);
fprintf (stderr, "size = %ld\n", (long) hdr->size);
fflush (stderr);
}
@ -4203,9 +4151,10 @@ elf_link_add_object_symbols (abfd, info)
else if (sym.st_shndx > 0 && sym.st_shndx < SHN_LORESERVE)
{
sec = section_from_elf_index (abfd, sym.st_shndx);
if (sec == NULL)
goto error_return;
value -= sec->vma;
if (sec != NULL)
value -= sec->vma;
else
sec = bfd_abs_section_ptr;
}
else if (sym.st_shndx == SHN_ABS)
sec = bfd_abs_section_ptr;
@ -5389,7 +5338,7 @@ elf_bfd_final_link (abfd, info)
for (i = 1; i < elf_elfheader (abfd)->e_shnum; i++)
{
o = section_from_elf_index (abfd, i);
if (! bfd_is_abs_section (o))
if (o != NULL)
o->target_index = abfd->symcount;
elfsym.st_shndx = i;
if (! elf_link_output_sym (&finfo, (const char *) NULL,
@ -6034,11 +5983,7 @@ elf_link_input_bfd (finfo, input_bfd)
if (isym->st_shndx == SHN_UNDEF)
isec = bfd_und_section_ptr;
else if (isym->st_shndx > 0 && isym->st_shndx < SHN_LORESERVE)
{
isec = section_from_elf_index (input_bfd, isym->st_shndx);
if (isec == NULL)
return false;
}
isec = section_from_elf_index (input_bfd, isym->st_shndx);
else if (isym->st_shndx == SHN_ABS)
isec = bfd_abs_section_ptr;
else if (isym->st_shndx == SHN_COMMON)

View File

@ -449,7 +449,6 @@ struct elf_obj_tdata
int num_globals;
Elf_Sym_Extra *sym_extra;
asymbol **section_syms; /* STT_SECTION symbols for each section */
int num_section_syms; /* number of section_syms allocated */
Elf_Internal_Shdr symtab_hdr;
Elf_Internal_Shdr shstrtab_hdr;
Elf_Internal_Shdr strtab_hdr;
@ -499,7 +498,6 @@ struct elf_obj_tdata
#define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals)
#define elf_sym_extra(bfd) (elf_tdata(bfd) -> sym_extra)
#define elf_section_syms(bfd) (elf_tdata(bfd) -> section_syms)
#define elf_num_section_syms(bfd) (elf_tdata(bfd) -> num_section_syms)
#define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo)
#define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus)
#define elf_gp(bfd) (elf_tdata(bfd) -> gp)