1 /* Copyright (C) 2001, 2005, 2006 Red Hat, Inc.
2 Written by Jakub Jelinek <jakub@redhat.com>, 2001.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
70 return *(uint32_t *)p;
76 return bswap_32 (*(uint32_t *)p);
80 write_native (char *p, uint32_t v)
86 write_swap (char *p, uint32_t v)
88 *(uint32_t *)p = bswap_32 (v);
92 adjust_stabs (DSO *dso, int n, GElf_Addr start, GElf_Addr adjust)
94 Elf_Data *data = NULL;
95 Elf_Scn *scn = dso->scn[n];
97 uint32_t (*read_32) (char *p);
98 void (*write_32) (char *p, uint32_t v);
102 assert (dso->shdr[n].sh_entsize == 12);
103 data = elf_getdata (scn, NULL);
104 assert (data != NULL && data->d_buf != NULL);
105 assert (elf_getdata (scn, data) == NULL);
106 assert (data->d_off == 0 && data->d_size == dso->shdr[n].sh_size);
107 #if __BYTE_ORDER == __BIG_ENDIAN
108 if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
109 #elif __BYTE_ORDER == __LITTLE_ENDIAN
110 if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
112 # error Not supported host endianess
115 read_32 = read_native;
116 write_32 = write_native;
118 #if __BYTE_ORDER == __BIG_ENDIAN
119 else if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
120 #elif __BYTE_ORDER == __LITTLE_ENDIAN
121 else if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
125 write_32 = write_swap;
129 error (0, 0, "%s: Wrong ELF data enconding", dso->filename);
133 for (off = 0; off < data->d_size; off += 12)
135 switch ((type = *(uint8_t *)(data->d_buf + off + 4)))
138 /* If string is "", N_FUN is function length, otherwise
139 it is function start address. */
140 if (read_32 (data->d_buf + off) == 0)
150 value = read_32 (data->d_buf + off + 8);
151 sec = addr_to_sec (dso, value);
154 addr_adjust (value, start, adjust);
155 write_32 (data->d_buf + off + 8, value);
158 /* These should be always 0. */
165 /* These contain other values. */
173 /* These are relative. */
181 error (0, 0, "%s: Unknown stabs code 0x%02x\n", dso->filename, type);
186 elf_flagscn (scn, ELF_C_SET, ELF_F_DIRTY);