Deleted Added
full compact
elflink.c (33965) elflink.c (38889)
1/* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or

--- 19 unchanged lines hidden (view full) ---

28_bfd_elf_create_got_section (abfd, info)
29 bfd *abfd;
30 struct bfd_link_info *info;
31{
32 flagword flags;
33 register asection *s;
34 struct elf_link_hash_entry *h;
35 struct elf_backend_data *bed = get_elf_backend_data (abfd);
1/* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or

--- 19 unchanged lines hidden (view full) ---

28_bfd_elf_create_got_section (abfd, info)
29 bfd *abfd;
30 struct bfd_link_info *info;
31{
32 flagword flags;
33 register asection *s;
34 struct elf_link_hash_entry *h;
35 struct elf_backend_data *bed = get_elf_backend_data (abfd);
36 int ptralign;
36
37 /* This function may be called more than once. */
38 if (bfd_get_section_by_name (abfd, ".got") != NULL)
39 return true;
40
37
38 /* This function may be called more than once. */
39 if (bfd_get_section_by_name (abfd, ".got") != NULL)
40 return true;
41
42 switch (bed->s->arch_size)
43 {
44 case 32: ptralign = 2; break;
45 case 64: ptralign = 3; break;
46 default: abort();
47 }
48
41 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
42 | SEC_LINKER_CREATED);
43
44 s = bfd_make_section (abfd, ".got");
45 if (s == NULL
46 || !bfd_set_section_flags (abfd, s, flags)
49 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
50 | SEC_LINKER_CREATED);
51
52 s = bfd_make_section (abfd, ".got");
53 if (s == NULL
54 || !bfd_set_section_flags (abfd, s, flags)
47 || !bfd_set_section_alignment (abfd, s, 2))
55 || !bfd_set_section_alignment (abfd, s, ptralign))
48 return false;
49
50 if (bed->want_got_plt)
51 {
52 s = bfd_make_section (abfd, ".got.plt");
53 if (s == NULL
54 || !bfd_set_section_flags (abfd, s, flags)
56 return false;
57
58 if (bed->want_got_plt)
59 {
60 s = bfd_make_section (abfd, ".got.plt");
61 if (s == NULL
62 || !bfd_set_section_flags (abfd, s, flags)
55 || !bfd_set_section_alignment (abfd, s, 2))
63 || !bfd_set_section_alignment (abfd, s, ptralign))
56 return false;
57 }
58
59 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
60 (or .got.plt) section. We don't do this in the linker script
61 because we don't want to define the symbol if we are not creating
62 a global offset table. */
63 h = NULL;
64 if (!(_bfd_generic_link_add_one_symbol
64 return false;
65 }
66
67 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
68 (or .got.plt) section. We don't do this in the linker script
69 because we don't want to define the symbol if we are not creating
70 a global offset table. */
71 h = NULL;
72 if (!(_bfd_generic_link_add_one_symbol
65 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, (bfd_vma) 0,
66 (const char *) NULL, false, get_elf_backend_data (abfd)->collect,
67 (struct bfd_link_hash_entry **) &h)))
73 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
74 bed->got_symbol_offset, (const char *) NULL, false,
75 bed->collect, (struct bfd_link_hash_entry **) &h)))
68 return false;
69 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
70 h->type = STT_OBJECT;
71
72 if (info->shared
73 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
74 return false;
75
76 elf_hash_table (info)->hgot = h;
77
76 return false;
77 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
78 h->type = STT_OBJECT;
79
80 if (info->shared
81 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
82 return false;
83
84 elf_hash_table (info)->hgot = h;
85
78 /* The first three global offset table entries are reserved. */
79 s->_raw_size += 3 * 4;
86 /* The first three global offset table entries after
87 '_GLOBAL_OFFSET_TABLE_' are reserved. */
88 s->_raw_size += (3 << ptralign) + bed->got_symbol_offset;
80
81 return true;
82}
83
84
85/* Create dynamic sections when linking against a dynamic object. */
86
87boolean
88_bfd_elf_create_dynamic_sections (abfd, info)
89 bfd *abfd;
90 struct bfd_link_info *info;
91{
89
90 return true;
91}
92
93
94/* Create dynamic sections when linking against a dynamic object. */
95
96boolean
97_bfd_elf_create_dynamic_sections (abfd, info)
98 bfd *abfd;
99 struct bfd_link_info *info;
100{
92 flagword flags;
101 flagword flags, pltflags;
93 register asection *s;
94 struct elf_backend_data *bed = get_elf_backend_data (abfd);
102 register asection *s;
103 struct elf_backend_data *bed = get_elf_backend_data (abfd);
104 int ptralign;
95
105
106 switch (bed->s->arch_size)
107 {
108 case 32: ptralign = 2; break;
109 case 64: ptralign = 3; break;
110 default: abort();
111 }
112
96 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
97 .rel[a].bss sections. */
98
99 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
100 | SEC_LINKER_CREATED);
101
113 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
114 .rel[a].bss sections. */
115
116 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
117 | SEC_LINKER_CREATED);
118
119 pltflags = flags;
120 pltflags |= SEC_CODE;
121 if (bed->plt_not_loaded)
122 pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
123 if (bed->plt_readonly)
124 pltflags |= SEC_READONLY;
125
102 s = bfd_make_section (abfd, ".plt");
103 if (s == NULL
126 s = bfd_make_section (abfd, ".plt");
127 if (s == NULL
104 || ! bfd_set_section_flags (abfd, s,
105 (flags | SEC_CODE
106 | (bed->plt_readonly ? SEC_READONLY : 0)))
107 || ! bfd_set_section_alignment (abfd, s, 2))
128 || ! bfd_set_section_flags (abfd, s, pltflags)
129 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
108 return false;
109
110 if (bed->want_plt_sym)
111 {
112 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
113 .plt section. */
114 struct elf_link_hash_entry *h = NULL;
115 if (! (_bfd_generic_link_add_one_symbol

--- 8 unchanged lines hidden (view full) ---

124 if (info->shared
125 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
126 return false;
127 }
128
129 s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.plt" : ".rel.plt");
130 if (s == NULL
131 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
130 return false;
131
132 if (bed->want_plt_sym)
133 {
134 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
135 .plt section. */
136 struct elf_link_hash_entry *h = NULL;
137 if (! (_bfd_generic_link_add_one_symbol

--- 8 unchanged lines hidden (view full) ---

146 if (info->shared
147 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
148 return false;
149 }
150
151 s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.plt" : ".rel.plt");
152 if (s == NULL
153 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
132 || ! bfd_set_section_alignment (abfd, s, 2))
154 || ! bfd_set_section_alignment (abfd, s, ptralign))
133 return false;
134
135 if (! _bfd_elf_create_got_section (abfd, info))
136 return false;
137
138 /* The .dynbss section is a place to put symbols which are defined
139 by dynamic objects, are referenced by regular objects, and are
140 not functions. We must allocate space for them in the process

--- 16 unchanged lines hidden (view full) ---

157 be needed, we can discard it later. We will never need this
158 section when generating a shared object, since they do not use
159 copy relocs. */
160 if (! info->shared)
161 {
162 s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.bss" : ".rel.bss");
163 if (s == NULL
164 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
155 return false;
156
157 if (! _bfd_elf_create_got_section (abfd, info))
158 return false;
159
160 /* The .dynbss section is a place to put symbols which are defined
161 by dynamic objects, are referenced by regular objects, and are
162 not functions. We must allocate space for them in the process

--- 16 unchanged lines hidden (view full) ---

179 be needed, we can discard it later. We will never need this
180 section when generating a shared object, since they do not use
181 copy relocs. */
182 if (! info->shared)
183 {
184 s = bfd_make_section (abfd, bed->use_rela_p ? ".rela.bss" : ".rel.bss");
185 if (s == NULL
186 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
165 || ! bfd_set_section_alignment (abfd, s, 2))
187 || ! bfd_set_section_alignment (abfd, s, ptralign))
166 return false;
167 }
168
169 return true;
170}
171
172
173/* Record a new dynamic symbol. We record the dynamic symbols as we

--- 239 unchanged lines hidden ---
188 return false;
189 }
190
191 return true;
192}
193
194
195/* Record a new dynamic symbol. We record the dynamic symbols as we

--- 239 unchanged lines hidden ---