summaryrefslogtreecommitdiff
path: root/toolchain/elf2flt/elf2flt.nios2.conditional
blob: 42b24b8fa891708ba363fd90e5e6068b968480b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
--- elf2flt/Makefile.in
+++ elf2flt/Makefile.in
@@ -34,6 +34,12 @@ else 
 SRC_LDFILE= elf2flt.ld
 endif
 
+ifeq ($(strip $(CPU)),nios2)
+SRC_LDFILE= $(CPU)-elf2flt.ld
+else 
+SRC_LDFILE= elf2flt.ld
+endif
+
 target_bindir = $(prefix)/$(TARGET)/bin
 target_libdir = $(prefix)/$(TARGET)/lib
 
--- elf2flt/elf2flt.c
+++ elf2flt/elf2flt.c
@@ -553,9 +553,11 @@ dump_symbols(symbols, number_of_symbols)
 	 *	Only relocate things in the data sections if we are PIC/GOT.
 	 *	otherwise do text as well
 	 */
-	if (!pic_with_got && (a->flags & SEC_CODE))
+// wentao	if (!pic_with_got && (a->flags & SEC_CODE))
+	if (!pic_with_got && (strcmp(".text", a->name) == 0))
 		sectionp = text + (a->vma - text_vma);
-	else if (a->flags & SEC_DATA)
+//	wentao else if (a->flags & SEC_DATA)
+	else if (strcmp(".data", a->name) == 0)
 		sectionp = data + (a->vma - data_vma);
 	else
 		continue;
@@ -926,8 +928,7 @@ dump_symbols(symbols, number_of_symbols)
 						bad_relocs++;
 						continue;
 					}
-					/* Absolute symbol done not relocation */
-					relocation_needed = !bfd_is_abs_section(sym_section);
+					relocation_needed = 1;
 					sym_addr = (*(q->sym_ptr_ptr))->value;
 					sym_vma = bfd_section_vma(abs_bfd, sym_section);
 					sym_addr += sym_vma + q->addend;
@@ -1013,19 +1014,10 @@ dump_symbols(symbols, number_of_symbols)
 
 					/* grab any offset from the text */
 					offset = (p[0]<<24) + (p[1] << 16) + (p[2] << 8) + (p[3]);
+					//sym_addr = (*(q->sym_ptr_ptr))->value;
 					sym_vma = bfd_section_vma(abs_bfd, sym_section);
-					/* This is a horrible kludge.  For some
-					   reason, *sometimes* the offset is in
-					   both addend and the code.  Detect
-					   it, and cancel the effect.  Otherwise
-					   the offset gets added twice - ouch.
-					   There should be a better test
-					   for this condition, based on the
-					   BFD data structures */
-					if(offset==q->addend)
-						offset=0;
-
 					sym_addr += offset + sym_vma + q->addend;
+
 					relocation_needed = 1;
 					break;
 				}
@@ -1848,32 +1840,27 @@ int main(int argc, char *argv[])
   /* Group output sections into text, data, and bss, and calc their sizes.  */
   for (s = abs_bfd->sections; s != NULL; s = s->next) {
     unsigned long *vma, *len;
-    bfd_size_type sec_size;
-    bfd_vma sec_vma;
 
-    if (s->flags & SEC_CODE) {
+	if (strcmp(s->name, ".text") == 0) /*wentao    if (s->flags & SEC_CODE)*/ {
       vma = &text_vma;
       len = &text_len;
-    } else if (s->flags & SEC_DATA) {
+    } else if (strcmp(s->name, ".data") == 0) /* wentao (s->flags & SEC_DATA)*/ {
       vma = &data_vma;
       len = &data_len;
-    } else if (s->flags & SEC_ALLOC) {
+    } else if (strcmp(s->name, ".bss") == 0) /*(s->flags & SEC_ALLOC)*/ {
       vma = &bss_vma;
       len = &bss_len;
     } else
       continue;
 
-    sec_size = bfd_section_size(abs_bfd, s);
-    sec_vma  = bfd_section_vma(abs_bfd, s);
-
-    if (sec_vma < *vma) {
+    if (s->vma < *vma) {
       if (*len > 0)
-	*len += sec_vma - *vma;
+	*len += s->vma - *vma;
       else
-	*len = sec_size;
-      *vma = sec_vma;
-    } else if (sec_vma + sec_size > *vma + *len)
-      *len = sec_vma + sec_size - *vma;
+	*len = s->_raw_size;
+      *vma = s->vma;
+    } else if (s->vma + s->_raw_size > *vma + *len)
+      *len = s->vma + s->_raw_size - *vma;
   }
 
   if (text_len == 0) {
@@ -1888,10 +1875,10 @@ int main(int argc, char *argv[])
 
   /* Read in all text sections.  */
   for (s = abs_bfd->sections; s != NULL; s = s->next)
-    if (s->flags & SEC_CODE) 
+    if (strcmp(s->name, ".text") == 0) /* wentao (s->flags & SEC_CODE) */
       if (!bfd_get_section_contents(abs_bfd, s,
 				   text + (s->vma - text_vma), 0,
-				   bfd_section_size(abs_bfd, s)))
+				   s->_raw_size))
       {
 	fprintf(stderr, "read error section %s\n", s->name);
 	exit(2);
@@ -1919,10 +1906,10 @@ int main(int argc, char *argv[])
 
   /* Read in all data sections.  */
   for (s = abs_bfd->sections; s != NULL; s = s->next)
-    if (s->flags & SEC_DATA) 
+    if (strcmp(s->name, ".data") == 0) /* wentao (s->flags & SEC_DATA)*/ 
       if (!bfd_get_section_contents(abs_bfd, s,
 				   data + (s->vma - data_vma), 0,
-				   bfd_section_size(abs_bfd, s)))
+				   s->_raw_size))
       {
 	fprintf(stderr, "read error section %s\n", s->name);
 	exit(2);
--- elf2flt/nios2-elf2flt.ld
+++ elf2flt/nios2-elf2flt.ld
@@ -0,0 +1,126 @@
+ENTRY (_start)
+
+MEMORY {
+        flatmem : ORIGIN = 0x0, LENGTH = 0xfffffff
+}
+
+SECTIONS {
+        .text 0 : {
+		/* Avoid address 0; binfmt_flat treats it specially.  */
+		. = . + 4 ;
+
+                . = ALIGN(0x4) ;
+                _stext = . ;
+
+                *(.text)
+                *(.text.*)
+                *(.gnu.warning)
+                *(.stub)
+                *(.gnu.linkonce.t*)
+				*(.jcr)
+                *(.init)
+                *(.fini)
+
+		/* This is special code area at the end of the normal
+		   text section.  It contains a small lookup table at
+		   the start followed by the code pointed to by entries
+		   in the lookup table.  */
+		. = ALIGN (4) ;
+		PROVIDE(__ctbp = .);
+		*(.call_table_data)
+		*(.call_table_text)
+
+		. = ALIGN(0x10) ;
+		_etext = . ;
+        } > flatmem
+        .data : {
+                . = ALIGN(0x4) ;
+                _sdata = . ;
+				__data_start = . ;
+				data_start = . ;
+				*(.rela.got)
+				*(.rel.got)
+				*(.got.plt)
+				*(.got)
+				LONG(-1)
+                *(.rodata)
+                *(.rodata1)
+                *(.rodata.*)
+                *(.gnu.linkonce.r*)
+                *(.data)
+                *(.data.*)
+                *(.gnu.linkonce.d*)
+                *(.data1)
+                *(.eh_frame)
+                *(.gcc_except_table)
+				. = ALIGN(4) ;
+				*(.ctors.*)
+				*(.ctors)
+				LONG(0)
+				*(.dtors.*)
+				*(.dtors)
+				LONG(0)
+                . = ALIGN(0x10) ;
+
+				_gp = ABSOLUTE(ALIGN(16) + 0x7ff0);
+		  		PROVIDE(gp = _gp);
+                *(.sdata) 
+                *(.sdata.*)
+                *(.sbss)
+                *(.gnu.linkonce.s.*)
+                _edata = . ;
+        } > flatmem
+        .bss : {
+                . = ALIGN(0x4) ;
+                _sbss = ALIGN(0x4) ;
+				__bss_start = . ;
+                *(.dynsbss)
+                *(.sbss)
+                *(.sbss.*)
+                *(.scommon)
+                *(.dynbss)
+                *(.bss)
+                *(.bss.*)
+                *(COMMON)
+                . = ALIGN(0x4) ;
+                _ebss = . ;
+				_end = . ;
+				end = . ;
+        } > flatmem
+        
+  .junk 0 : { *(.rel*) *(.rela*) }
+  /* Stabs debugging sections.  */
+  .stab 0 : { *(.stab) }
+  .stabstr 0 : { *(.stabstr) }
+  .stab.excl 0 : { *(.stab.excl) }
+  .stab.exclstr 0 : { *(.stab.exclstr) }
+  .stab.index 0 : { *(.stab.index) }
+  .stab.indexstr 0 : { *(.stab.indexstr) }
+  .comment 0 : { *(.comment) }
+  /* DWARF debug sections.
+     Symbols in the DWARF debugging sections are relative to the beginning
+     of the section so we begin them at 0.  */
+  /* DWARF 1 */
+  .debug          0 : { *(.debug) }
+  .line           0 : { *(.line) }
+  /* GNU DWARF 1 extensions */
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
+  .debug_sfnames  0 : { *(.debug_sfnames) }
+  /* DWARF 1.1 and DWARF 2 */
+  .debug_aranges  0 : { *(.debug_aranges) }
+  .debug_pubnames 0 : { *(.debug_pubnames) }
+  /* DWARF 2 */
+  .debug_info     0 : { *(.debug_info) }
+  .debug_abbrev   0 : { *(.debug_abbrev) }
+  .debug_line     0 : { *(.debug_line) }
+  .debug_frame    0 : { *(.debug_frame) }
+  .debug_str      0 : { *(.debug_str) }
+  .debug_loc      0 : { *(.debug_loc) }
+  .debug_macinfo  0 : { *(.debug_macinfo) }
+  /* SGI/MIPS DWARF 2 extensions */
+  .debug_weaknames 0 : { *(.debug_weaknames) }
+  .debug_funcnames 0 : { *(.debug_funcnames) }
+  .debug_typenames 0 : { *(.debug_typenames) }
+  .debug_varnames  0 : { *(.debug_varnames) }
+  /* These must appear regardless of  .  */        
+}
--- elf2flt/ld-elf2flt.in
+++ elf2flt/ld-elf2flt.in
@@ -15,13 +15,9 @@
 LINKER="$0.real"            # the original renamed-linker
 ELF2FLT="`expr $0 : '\(.*\)ld'`elf2flt"
 TOOLDIR="`dirname $0`"      # let gcc find the tools for us
-LDSCRIPTPATH="${TOOLDIR}/../@target_alias@/lib"		# and the scripts
 SHARED_ID=""
 NEWLDSCRIPT=""
 
-# check TOOLDIR from prefix/bin/ or prefix/target-alias/bin/
-[ -d "${TOOLDIR}/../@target_alias@/lib" ] || LDSCRIPTPATH="${TOOLDIR}/../lib"
-
 #
 # if we have the elf2flt options, run it
 #
@@ -77,9 +73,6 @@ then
 				  VERBOSE="y"
 				  ;;
 
-		-m)       shift; EMUL="-m $1";;        # ld emulations for h8300
-		-m*)      EMUL=$1;;
- 
 		*)        ARG1="$ARG1 $1"
 				  ;;
 		esac
@@ -120,37 +113,33 @@ then
 			fi
 
 			# Provide the magic parameter that defines the library data segment pointer offset
-			case "@target_cpu@" in
-			    h8300) GOT_OFFSET="__current_shared_library_er5_offset_";;
-			    *)     GOT_OFFSET="_current_shared_library_a5_offset_";;
-			esac
-			ARG1="$ARG1 -defsym $GOT_OFFSET=`expr ${SHARED_ID} '*' -4 - 4`"
+			ARG1="$ARG1 -defsym _current_shared_library_a5_offset_=`expr ${SHARED_ID} '*' -4 - 4`"
 		fi
 		
 		# provide a default linker script, we usually need one
-		[ -z "$LDSCRIPT" ] && LDSCRIPT="${LDSCRIPTPATH}/elf2flt.ld"
+		[ -z "$LDSCRIPT" ] && LDSCRIPT="@prefix@/@target_alias@/lib/elf2flt.ld"
 
 		# if we can find the linker script we preprocess it,  otherwise
 		# we assume the user knows what they are doing
 		if [ -f "$LDSCRIPT" ]; then
 			sed $SEDOP < "$LDSCRIPT" > "$NEWLDSCRIPT"
 			LDSCRIPT="$NEWLDSCRIPT"
-		elif [ -f "${LDSCRIPTPATH}/$LDSCRIPT" ]; then
-			sed $SEDOP < "${LDSCRIPTPATH}/$LDSCRIPT" > "$NEWLDSCRIPT"
+		elif [ -f "@prefix@/@target_alias@/lib/$LDSCRIPT" ]; then
+			sed $SEDOP < "@prefix@/@target_alias@/lib/$LDSCRIPT" > "$NEWLDSCRIPT"
 			LDSCRIPT="$NEWLDSCRIPT"
-		elif [ -f "${LDSCRIPTPATH}/ldscripts/$LDSCRIPT" ]; then
-			sed $SEDOP < "${LDSCRIPTPATH}/ldscripts/$LDSCRIPT" > "$NEWLDSCRIPT"
+		elif [ -f "@prefix@/@target_alias@/lib/ldscripts/$LDSCRIPT" ]; then
+			sed $SEDOP < "@prefix@/@target_alias@/lib/ldscripts/$LDSCRIPT" > "$NEWLDSCRIPT"
 			LDSCRIPT="$NEWLDSCRIPT"
 		fi
 
 		if [ "@got_check@" = "no" ]
 		then
-		 $LINKER $EMUL $SDIRS -T $LDSCRIPT -Ur -d -o "$OFILE.elf" $ARG1         ||exit $?
-		 $LINKER $EMUL $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" $ARG1                ||exit $?
+		 $LINKER $SDIRS -T $LDSCRIPT -Ur -d -o "$OFILE.elf" $ARG1         ||exit $?
+		 $LINKER $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" $ARG1                ||exit $?
 		else
-		 $LINKER $EMUL -r -d -o "$OFILE.elf2flt" $ARG1                          ||exit $?
-		 $LINKER $EMUL $SDIRS -T $LDSCRIPT -Ur -o "$OFILE.elf" "$OFILE.elf2flt" ||exit $?
-		 $LINKER $EMUL $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" "$OFILE.elf2flt"     ||exit $?
+		 $LINKER -r -d -o "$OFILE.elf2flt" $ARG1                          ||exit $?
+		 $LINKER $SDIRS -T $LDSCRIPT -Ur -o "$OFILE.elf" "$OFILE.elf2flt" ||exit $?
+		 $LINKER $SDIRS -T $LDSCRIPT -o "$OFILE.gdb" "$OFILE.elf2flt"     ||exit $?
 		 rm -f "$OFILE.elf2flt"
 		fi
 		if grep _GLOBAL_OFFSET_TABLE_ "$OFILE.gdb" > /dev/null