annotate packages/services/objloader/current/src/objelf.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents 6fd46febe457
children f8dd12428f1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
1 /* =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
2 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
3 * objelf.c
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
4 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
5 * Relocation routine for eCos loader.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
6 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
7 * =================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
8 * ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
9 * -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
10 * This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
11 * Copyright (C) 2005 Free Software Foundation, Inc.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
12 *
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
13 * eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
14 * the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
15 * Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
16 * version.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
17 *
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
18 * eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
21 * for more details.
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
22 *
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
23 * You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
24 * along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
26 *
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
27 * As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
28 * macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
29 * and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
30 * this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
31 * the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
32 * must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
33 * General Public License v2.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
34 *
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
35 * This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
36 * on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
37 * -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2243
diff changeset
38 * ####ECOSGPLCOPYRIGHTEND####
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
39 * =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
40 * #####DESCRIPTIONBEGIN####
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
41 *
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
42 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
43 * Contributors: nickg@ecoscentric.com
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
44 * Date: 2005-05-13
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
45 * Purpose:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
46 * Description:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
47 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
48 * ####DESCRIPTIONEND####
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
49 *
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
50 * =================================================================
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
51 */
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
52
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
53 #include <cyg/infra/diag.h> // For diagnostic printing.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
54 #include <pkgconf/io_fileio.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
55 #include <cyg/hal/hal_tables.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
56 #include <stdio.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
57
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
58 #include <pkgconf/objloader.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
59 #include <cyg/objloader/elf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
60 #include <cyg/objloader/objelf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
61
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
62 CYG_HAL_TABLE_BEGIN(cyg_ldr_table, ldr_table);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
63 CYG_HAL_TABLE_END(cyg_ldr_table_end, ldr_table);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
64
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
65 __externC cyg_ldr_table_entry cyg_ldr_table[];
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
66 __externC cyg_ldr_table_entry cyg_ldr_table_end[];
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
67
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
68 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
69 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
70 cyg_ldr_print_section_data(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
71 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
72 int i;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
73 char strname[32];
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
74 char *p_strtab = (char*)p->sections[p->p_elfhdr->e_shstrndx];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
75
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
76 diag_printf("\n\nSection Headers:\n");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
77 diag_printf("[Nr] Name Addr Offset Size Info\n");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
78 for (i = 0; i < p->p_elfhdr->e_shnum; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
79 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
80 sprintf(strname, "%s", p_strtab + p->p_sechdr[i].sh_name);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
81 while (strlen(strname) < 20)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
82 strcat(strname, " ");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
83 diag_printf("[%02d] %s %08X %08X %08X %08X\n",
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
84 i,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
85 strname,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
86 p->p_sechdr[i].sh_addr,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
87 p->p_sechdr[i].sh_offset,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
88 p->p_sechdr[i].sh_size,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
89 p->p_sechdr[i].sh_info);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
90 }
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
91 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
92 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
93
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
94 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
95 cyg_ldr_print_symbol_names(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
96 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
97 int i;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
98 Elf32_Sym *p_symtab = (Elf32_Sym*)p->sections[p->hdrndx_symtab];
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
99 char *p_strtab = (char*)p->sections[p->hdrndx_strtab];
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
100 char strname[32];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
101
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
102 // Total number of entries in the symbol table.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
103 int symtab_entries = p->p_sechdr[p->hdrndx_symtab].sh_size /
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
104 p->p_sechdr[p->hdrndx_symtab].sh_entsize;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
105 diag_printf("Num Value Size Ndx Name\n");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
106 for (i = 1; i < symtab_entries; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
107 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
108 sprintf(strname, "%d", i);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
109 while (strlen(strname) < 5)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
110 strcat(strname, " ");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
111 diag_printf(strname);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
112
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
113 sprintf(strname,
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
114 "%08X %d",
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
115 p_symtab[i].st_value,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
116 p_symtab[i].st_size);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
117 while (strlen(strname) < 15)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
118 strcat(strname, " ");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
119 diag_printf(strname);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
120
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
121 sprintf(strname, "%d", p_symtab[i].st_shndx);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
122 while (strlen(strname) < 6)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
123 strcat(strname, " ");
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
124 diag_printf(strname);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
125
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
126 strncpy(strname,
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
127 p_strtab + p_symtab[i].st_name,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
128 sizeof(strname) - 1);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
129 strname[strlen(p_strtab + p_symtab[i].st_name)] = '\0';
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
130 diag_printf(strname);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
131 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
132 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
133 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
134
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
135 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
136 cyg_ldr_print_rel_names(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
137 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
138 int i, j, r_entries, sym_index;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
139 Elf32_Sym *p_symtab = (Elf32_Sym*)p->sections[p->hdrndx_symtab];
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
140 char *p_strtab = (char*)p->sections[p->hdrndx_strtab];
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
141 char *p_shstrtab = (char*)p->sections[p->p_elfhdr->e_shstrndx];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
142 #if ELF_ARCH_RELTYPE == Elf_Rela
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
143 Elf32_Rela* p_rela;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
144 #else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
145 Elf32_Rel* p_rel;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
146 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
147 char strname[32];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
148
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
149 for (i = 1; i < p->p_elfhdr->e_shnum; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
150 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
151 if ((p->p_sechdr[i].sh_type == SHT_REL) ||
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
152 (p->p_sechdr[i].sh_type == SHT_RELA))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
153 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
154 // Calculate the total number of entries in the .rela section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
155 r_entries = p->p_sechdr[i].sh_size / p->p_sechdr[i].sh_entsize;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
156
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
157 diag_printf("\n\nSymbols at: %s\n\n",
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
158 p_shstrtab + p->p_sechdr[i].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
159 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
160 p_rela = (Elf32_Rela*)cyg_ldr_load_elf_section(p, i);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
161 printf("Offset Info Name [+ Addend]\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
162 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
163 p_rel = (Elf32_Rel*)cyg_ldr_load_elf_section(p, i);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
164 printf("Offset Info Name\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
165 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
166
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
167 for (j = 0; j < r_entries; j++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
168 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
169 sprintf(strname,
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
170 "%08X %08X ",
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
171 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
172 p_rela[j].r_offset,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
173 p_rela[j].r_info
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
174 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
175 p_rel[j].r_offset,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
176 p_rel[j].r_info
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
177 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
178 );
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
179
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
180 diag_printf(strname);
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
181
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
182 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
183 cyg_uint8 sym_type = ELF32_R_SYM(p_rela[j].r_info);
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
184 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
185 cyg_uint8 sym_type = ELF32_R_SYM(p_rel[j].r_info);
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
186 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
187 if (strlen (p_strtab + p_symtab[sym_type].st_name) > 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
188 diag_printf(p_strtab + p_symtab[sym_type].st_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
189 else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
190 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
191 // If the symbol name is not available, then print
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
192 // the name of the section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
193 sym_index = p_symtab[sym_type].st_shndx;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
194 diag_printf(p_shstrtab + p->p_sechdr[sym_index].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
195 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
196 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
197 if (p_rela[j].r_addend != 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
198 diag_printf(" + %08X", p_rela[j].r_addend);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
199 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
200 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
201 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
202 // After all the printing is done, the relocation table can
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
203 // be dumped.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
204 cyg_ldr_delete_elf_section(p, i);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
205 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
206 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
207 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
208 #endif // DEBUG_PRINT
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
209
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
210 static void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
211 *cyg_ldr_local_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
212 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
213 cyg_uint32 data_sec, addr;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
214 Elf32_Sym *p_symtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
215
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
216 p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p, p->hdrndx_symtab);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
217
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
218 // Find out the section number in which the data for this symbol is
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
219 // located.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
220 data_sec = p_symtab[sym_index].st_shndx;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
221
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
222 // From the section number we get the start of the memory area in
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
223 // memory.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
224 addr = (cyg_uint32)cyg_ldr_section_address(p, data_sec);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
225
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
226 // And now return the address of the data.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
227 return (void*)(addr + p_symtab[sym_index].st_value);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
228 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
229
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
230 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
231 *cyg_ldr_external_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
232 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
233 cyg_uint8* tmp2;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
234 Elf32_Sym *p_symtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
235 cyg_uint8 *p_strtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
236 cyg_ldr_table_entry *entry = cyg_ldr_table;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
237
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
238
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
239 p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p, p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
240 p_strtab = (cyg_uint8*)cyg_ldr_section_address(p, p->hdrndx_strtab);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
241
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
242 // This is the name of the external reference to search.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
243 tmp2 = p_strtab + p_symtab[sym_index].st_name;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
244 while (entry != cyg_ldr_table_end)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
245 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
246 if (!strcmp((const char*)tmp2, entry->symbol_name ))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
247 return entry->handler;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
248 entry++;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
249 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
250
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
251 // Symbol not found.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
252 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
253 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
254
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
255 // input:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
256 // p : Pointer to the elf file object
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
257 // sym_index : Index of the symbol to be searched (in the SYMTAB)
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
258 //
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
259 // out:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
260 // 0 : Symbol not found
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
261 // Other : Address of the symbol in absolute memory.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
262 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
263 *cyg_ldr_symbol_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
264 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
265 cyg_uint32 addr;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
266 Elf32_Sym *p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
267 p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
268 cyg_uint8 sym_info = p_symtab[sym_index].st_info;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
269 switch (ELF32_ST_TYPE(sym_info))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
270 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
271 case STT_NOTYPE:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
272 case STT_FUNC:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
273 case STT_OBJECT:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
274 switch (ELF32_ST_BIND(sym_info))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
275 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
276 case STB_LOCAL:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
277 case STB_GLOBAL:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
278 if (p_symtab[sym_index].st_shndx == SHN_UNDEF)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
279 return cyg_ldr_external_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
280 else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
281 return cyg_ldr_local_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
282 case STB_WEAK:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
283 addr = (cyg_uint32)cyg_ldr_external_address(p, sym_index);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
284 if (addr != 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
285 return (void*)addr;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
286 else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
287 return cyg_ldr_local_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
288 default:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
289 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
290 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
291 break;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
292 case STT_SECTION:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
293 // Return the starting address of a section, given its index.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
294 return (void*)cyg_ldr_section_address(p, p_symtab[sym_index].st_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
295 default:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
296 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
297 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
298 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
299
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
300 // Loads the relocation information, relocates, and dumps the relocation
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
301 // information once the process is complete.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
302 cyg_int32
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
303 cyg_ldr_relocate_section(PELF_OBJECT p, cyg_uint32 r_shndx)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
304 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
305 int i, rc;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
306 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
307 Elf32_Rela* p_rela = (Elf32_Rela*)cyg_ldr_load_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
308 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
309 Elf32_Rel* p_rel = (Elf32_Rel*)cyg_ldr_load_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
310 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
311
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
312 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
313 Elf32_Sym *p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
314 p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
315 char *p_strtab = (char*)cyg_ldr_section_address(p, p->hdrndx_strtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
316 char *p_shstrtab = (char*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
317 p->p_elfhdr->e_shstrndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
318 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
319
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
320 // Now we can get the address of the contents of the section to modify.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
321 cyg_uint32 r_target_shndx = p->p_sechdr[r_shndx].sh_info;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
322 cyg_uint32 r_target_addr = (cyg_uint32)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
323 r_target_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
324
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
325 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
326 diag_printf("Relocating section \"%s\"\n",
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
327 p_shstrtab + p->p_sechdr[r_target_shndx].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
328 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
329 diag_printf("Ndx Type Offset Name\"\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
330 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
331 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
332
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
333 // Perform relocatation for each of the members of this table.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
334 cyg_uint32 r_entries = p->p_sechdr[r_shndx].sh_size /
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
335 p->p_sechdr[r_shndx].sh_entsize;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
336 for (i = 0; i < r_entries; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
337 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
338 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
339 Elf32_Addr r_offset = p_rela[i].r_offset;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
340 Elf32_Word r_type = ELF32_R_TYPE(p_rela[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
341 cyg_uint32 sym_index = ELF32_R_SYM(p_rela[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
342 Elf32_Sword r_addend = p_rela[i].r_addend;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
343 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
344 Elf32_Addr r_offset = p_rel[i].r_offset;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
345 Elf32_Word r_type = ELF32_R_TYPE(p_rel[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
346 cyg_uint32 sym_index = ELF32_R_SYM(p_rel[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
347 Elf32_Sword r_addend = 0;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
348 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
349
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
350 cyg_uint32 sym_value = (cyg_uint32)cyg_ldr_symbol_address(p, sym_index);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
351 if (sym_value == 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
352 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
353 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
354 diag_printf("Unknown symbol value: %s Index: %d\n",
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
355 p_strtab + p_symtab[sym_index].st_name,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
356 sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
357 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
358 return -1;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
359 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
360
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
361 // This is architecture dependent, and deals with whether we have
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
362 // '.rel' or '.rela' sections.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
363 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
364 diag_printf("%04X %04X %08X ",
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
365 sym_index,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
366 r_type,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
367 r_offset);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
368 if (strlen(p_strtab + p_symtab[sym_index].st_name) > 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
369 diag_printf(p_strtab + p_symtab[sym_index].st_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
370 else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
371 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
372 // If the symbol name is not available, then print
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
373 // the name of the section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
374 cyg_uint32 sec_ndx = p_symtab[sym_index].st_shndx;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
375 diag_printf(p_shstrtab + p->p_sechdr[sec_ndx].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
376 }
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
377 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
378 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
379 rc = cyg_ldr_relocate(r_type,
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
380 r_target_addr + r_offset,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
381 sym_value + r_addend);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
382 if (rc != 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
383 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
384 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
385 diag_printf("Relocation error: Cannot find symbol: %s\n",
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
386 p_strtab + p_symtab[sym_index].st_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
387 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
388 return -1;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
389 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
390 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
391
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
392 // After the relocation is done, the relocation table can be dumped.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
393 cyg_ldr_delete_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
394 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
395 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
396