annotate packages/services/objloader/current/src/objelf.c @ 2890:f8dd12428f1d

* cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c, src/relocate_arm.c: Eliminate dependency on CYGPKG_IO_FILEIO when the filesystem loader is not required. * src/relocate_arm.c : Added relocation software for the ARM . * src/relocate_i386.c : Added a structure containing the relocation names for every architecture. Only used (and compiled in) for pretty printing. * src/relocate_ppc.c : * include/relocate_arm.h : New header file for src/relocate_arm.c * cdl/objloader.cdl: Added the option to relocate for the ARM. * src/objloader.c : * src/objelf.c : Erased some redundant debug printout and improved the readability of the rest. * src/loader_memory.c : Added the code to allow the objloader package to load libraries from ROM memory, instead from a file system. The various sections of the library are the copied from ROM to RAM and relocated. * include/loader_memory.h : New header file for src/loader_memory.c * src/objloader.c : Added a line to include the loader_memory header file and code to flush the cache when calling cyg_ldr_find_symbol(). * cdl/objloader.cdl: Added one check boxe for each of the supported ways of loading libraries (two for now) so that the user can compile out the loading methods not used.
author jld
date Fri, 03 Jul 2009 14:49:44 +0000
parents 74dbf4c3f2e1
children 7cbaadc92c67
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.
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
11 * Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
2729
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 <cyg/hal/hal_tables.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
55 #include <stdio.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
56
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
57 #include <pkgconf/objloader.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
58 #include <cyg/objloader/elf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
59 #include <cyg/objloader/objelf.h>
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
60
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
61 CYG_HAL_TABLE_BEGIN(cyg_ldr_table, ldr_table);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
62 CYG_HAL_TABLE_END(cyg_ldr_table_end, ldr_table);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
63
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
64 __externC cyg_ldr_table_entry cyg_ldr_table[];
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
65 __externC cyg_ldr_table_entry cyg_ldr_table_end[];
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
66
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
67 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
68 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
69 cyg_ldr_print_section_data(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
70 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
71 int i;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
72 char strname[32];
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
73 char *p_strtab = (char*)p->sections[p->p_elfhdr->e_shstrndx];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
74
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
75 diag_printf("Section Headers:\n");
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
76 diag_printf("----------------------------------------------------------\n");
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
77 diag_printf("[Nr] Name Addr Offset"
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
78 " Size Info\n");
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
79 for (i = 0; i < p->p_elfhdr->e_shnum; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
80 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
81 sprintf(strname, "%s", p_strtab + p->p_sechdr[i].sh_name);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
82 while (strlen(strname) < 20)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
83 strcat(strname, " ");
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
84 diag_printf("[%2d] %s %08X %08X %08X %08X\n",
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
85 i,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
86 strname,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
87 p->p_sechdr[i].sh_addr,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
88 p->p_sechdr[i].sh_offset,
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
89 p->p_sechdr[i].sh_size,
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
90 p->p_sechdr[i].sh_info);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
91 }
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
92 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
93 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
94
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
95 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
96 cyg_ldr_print_symbol_names(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
97 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
98 int i;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
99 Elf32_Sym *p_symtab = (Elf32_Sym*)p->sections[p->hdrndx_symtab];
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
100 char *p_strtab = (char*)p->sections[p->hdrndx_strtab];
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
101 // char strname[32];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
102
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
103 // Total number of entries in the symbol table.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
104 int symtab_entries = p->p_sechdr[p->hdrndx_symtab].sh_size /
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
105 p->p_sechdr[p->hdrndx_symtab].sh_entsize;
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
106 diag_printf("Symbol Table Entries\n");
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
107 diag_printf("----------------------------------------\n");
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
108 diag_printf("[Nr] Value Size Ndx Name\n");
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
109 for (i = 1; i < symtab_entries; i++)
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
110 diag_printf("[%3d] %08X %04d %5d %s\n",
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
111 i,
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
112 p_symtab[i].st_value,
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
113 p_symtab[i].st_size,
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
114 p_symtab[i].st_shndx,
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
115 p_strtab + p_symtab[i].st_name);
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
116 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
117 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
118
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
119 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
120 cyg_ldr_print_rel_names(PELF_OBJECT p)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
121 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
122 int i, j, r_entries, sym_index;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
123 Elf32_Sym *p_symtab = (Elf32_Sym*)p->sections[p->hdrndx_symtab];
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
124 char *p_strtab = (char*)p->sections[p->hdrndx_strtab];
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
125 char *p_shstrtab = (char*)p->sections[p->p_elfhdr->e_shstrndx];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
126 #if ELF_ARCH_RELTYPE == Elf_Rela
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
127 Elf32_Rela* p_rela;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
128 #else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
129 Elf32_Rel* p_rel;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
130 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
131 char strname[32];
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
132
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
133 for (i = 1; i < p->p_elfhdr->e_shnum; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
134 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
135 if ((p->p_sechdr[i].sh_type == SHT_REL) ||
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
136 (p->p_sechdr[i].sh_type == SHT_RELA))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
137 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
138 // Calculate the total number of entries in the .rela section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
139 r_entries = p->p_sechdr[i].sh_size / p->p_sechdr[i].sh_entsize;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
140
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
141 diag_printf("\n\nSymbols at: %s\n\n",
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
142 p_shstrtab + p->p_sechdr[i].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
143 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
144 p_rela = (Elf32_Rela*)cyg_ldr_load_elf_section(p, i);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
145 printf("Offset Info Name [+ Addend]\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
146 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
147 p_rel = (Elf32_Rel*)cyg_ldr_load_elf_section(p, i);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
148 printf("Offset Info Name\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
149 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
150
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
151 for (j = 0; j < r_entries; j++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
152 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
153 sprintf(strname,
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
154 "%08X %08X ",
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
155 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
156 p_rela[j].r_offset,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
157 p_rela[j].r_info
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
158 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
159 p_rel[j].r_offset,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
160 p_rel[j].r_info
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
161 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
162 );
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
163
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
164 diag_printf(strname);
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
165
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
166 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
167 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
168 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
169 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
170 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
171 if (strlen (p_strtab + p_symtab[sym_type].st_name) > 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
172 diag_printf(p_strtab + p_symtab[sym_type].st_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
173 else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
174 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
175 // If the symbol name is not available, then print
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
176 // the name of the section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
177 sym_index = p_symtab[sym_type].st_shndx;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
178 diag_printf(p_shstrtab + p->p_sechdr[sym_index].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
179 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
180 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
181 if (p_rela[j].r_addend != 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
182 diag_printf(" + %08X", p_rela[j].r_addend);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
183 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
184 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
185 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
186 // After all the printing is done, the relocation table can
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
187 // be dumped.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
188 cyg_ldr_delete_elf_section(p, i);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
189 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
190 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
191 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
192 #endif // DEBUG_PRINT
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
193
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
194 static void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
195 *cyg_ldr_local_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
196 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
197 cyg_uint32 data_sec, addr;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
198 Elf32_Sym *p_symtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
199
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
200 p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p, p->hdrndx_symtab);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
201
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
202 // Find out the section number in which the data for this symbol is
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
203 // located.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
204 data_sec = p_symtab[sym_index].st_shndx;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
205
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
206 // From the section number we get the start of the memory area in
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
207 // memory.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
208 addr = (cyg_uint32)cyg_ldr_section_address(p, data_sec);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
209
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
210 // And now return the address of the data.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
211 return (void*)(addr + p_symtab[sym_index].st_value);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
212 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
213
2013
8bf90d16b837 * include/objelf.h: Include hal_tables.h otherwise we get strange
asl
parents: 2011
diff changeset
214 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
215 *cyg_ldr_external_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
216 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
217 cyg_uint8* tmp2;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
218 Elf32_Sym *p_symtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
219 cyg_uint8 *p_strtab;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
220 cyg_ldr_table_entry *entry = cyg_ldr_table;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
221
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
222
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
223 p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p, p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
224 p_strtab = (cyg_uint8*)cyg_ldr_section_address(p, p->hdrndx_strtab);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
225
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
226 // This is the name of the external reference to search.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
227 tmp2 = p_strtab + p_symtab[sym_index].st_name;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
228 while (entry != cyg_ldr_table_end)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
229 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
230 if (!strcmp((const char*)tmp2, entry->symbol_name ))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
231 return entry->handler;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
232 entry++;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
233 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
234
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
235 // Symbol not found.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
236 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
237 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
238
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
239 // input:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
240 // p : Pointer to the elf file object
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
241 // sym_index : Index of the symbol to be searched (in the SYMTAB)
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
242 //
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
243 // out:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
244 // 0 : Symbol not found
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
245 // Other : Address of the symbol in absolute memory.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
246 void
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
247 *cyg_ldr_symbol_address(PELF_OBJECT p, cyg_uint32 sym_index)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
248 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
249 cyg_uint32 addr;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
250 Elf32_Sym *p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
251 p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
252 cyg_uint8 sym_info = p_symtab[sym_index].st_info;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
253 switch (ELF32_ST_TYPE(sym_info))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
254 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
255 case STT_NOTYPE:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
256 case STT_FUNC:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
257 case STT_OBJECT:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
258 switch (ELF32_ST_BIND(sym_info))
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
259 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
260 case STB_LOCAL:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
261 case STB_GLOBAL:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
262 if (p_symtab[sym_index].st_shndx == SHN_UNDEF)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
263 return cyg_ldr_external_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
264 else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
265 return cyg_ldr_local_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
266 case STB_WEAK:
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
267 addr = (cyg_uint32)cyg_ldr_external_address(p, sym_index);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
268 if (addr != 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
269 return (void*)addr;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
270 else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
271 return cyg_ldr_local_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
272 default:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
273 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
274 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
275 break;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
276 case STT_SECTION:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
277 // Return the starting address of a section, given its index.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
278 return (void*)cyg_ldr_section_address(p, p_symtab[sym_index].st_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
279 default:
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
280 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
281 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
282 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
283
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
284 // Loads the relocation information, relocates, and dumps the relocation
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
285 // information once the process is complete.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
286 cyg_int32
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
287 cyg_ldr_relocate_section(PELF_OBJECT p, cyg_uint32 r_shndx)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
288 {
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
289 int i, rc;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
290 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
291 Elf32_Rela* p_rela = (Elf32_Rela*)cyg_ldr_load_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
292 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
293 Elf32_Rel* p_rel = (Elf32_Rel*)cyg_ldr_load_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
294 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
295
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
296 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
297 Elf32_Sym *p_symtab = (Elf32_Sym*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
298 p->hdrndx_symtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
299 char *p_strtab = (char*)cyg_ldr_section_address(p, p->hdrndx_strtab);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
300 char *p_shstrtab = (char*)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
301 p->p_elfhdr->e_shstrndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
302 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
303
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
304 // 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
305 cyg_uint32 r_target_shndx = p->p_sechdr[r_shndx].sh_info;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
306 cyg_uint32 r_target_addr = (cyg_uint32)cyg_ldr_section_address(p,
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
307 r_target_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
308
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
309 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 0
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
310 diag_printf("Relocating section \"%s\"\n",
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
311 p_shstrtab + p->p_sechdr[r_target_shndx].sh_name);
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
312 diag_printf("----------------------------------------\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
313 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
314 diag_printf(" Ndx Type Offset Name\"\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
315 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
316 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
317
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
318 // Perform relocatation for each of the members of this table.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
319 cyg_uint32 r_entries = p->p_sechdr[r_shndx].sh_size /
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
320 p->p_sechdr[r_shndx].sh_entsize;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
321 for (i = 0; i < r_entries; i++)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
322 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
323 #if ELF_ARCH_RELTYPE == Elf_Rela
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
324 Elf32_Addr r_offset = p_rela[i].r_offset;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
325 Elf32_Word r_type = ELF32_R_TYPE(p_rela[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
326 cyg_uint32 sym_index = ELF32_R_SYM(p_rela[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
327 Elf32_Sword r_addend = p_rela[i].r_addend;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
328 #else
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
329 Elf32_Addr r_offset = p_rel[i].r_offset;
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
330 Elf32_Word r_type = ELF32_R_TYPE(p_rel[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
331 cyg_uint32 sym_index = ELF32_R_SYM(p_rel[i].r_info);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
332 Elf32_Sword r_addend = 0;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
333 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
334
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
335 cyg_uint32 sym_value = (cyg_uint32)cyg_ldr_symbol_address(p, sym_index);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
336
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
337 // This is architecture dependent, and deals with whether we have
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
338 // '.rel' or '.rela' sections.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
339 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
340 diag_printf("%5d %s %08X ",
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
341 sym_index,
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
342 relocation_name[r_type],
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
343 r_offset);
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
344 if (strlen(p_strtab + p_symtab[sym_index].st_name) > 0)
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
345 diag_printf(p_strtab + p_symtab[sym_index].st_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
346 else
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
347 {
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
348 // If the symbol name is not available, then print
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
349 // the name of the section.
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
350 cyg_uint32 sec_ndx = p_symtab[sym_index].st_shndx;
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
351 diag_printf(p_shstrtab + p->p_sechdr[sec_ndx].sh_name);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
352 }
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
353 diag_printf("\n");
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
354 #endif
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
355 rc = cyg_ldr_relocate(r_type,
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
356 r_target_addr + r_offset,
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
357 sym_value + r_addend);
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
358 if (rc != 0)
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
359 {
2890
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
360 #if CYGPKG_SERVICES_OBJLOADER_DEBUG_LEVEL > 1
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
361 diag_printf("Error while relocating symbol: %s\n",
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
362 p_strtab + p_symtab[sym_index].st_name);
f8dd12428f1d * cdl/objloader.cdl, src/objelf.c, src/relocate_ppc.c,
jld
parents: 2729
diff changeset
363 return -1;
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
364 #endif
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
365 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
366 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
367
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
368 // After the relocation is done, the relocation table can be dumped.
2243
6fd46febe457 Warnings, cosmetic fixes from Anthony Tonizzo
gthomas
parents: 2013
diff changeset
369 cyg_ldr_delete_elf_section(p, r_shndx);
2011
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
370 return 0;
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
371 }
662e1b34b811 Added OBJLOADER package.
nickg
parents:
diff changeset
372