1 /* Support for 32-bit PowerPC NLM (NetWare Loadable Module)
2 Copyright 1994, 1995, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* The format of a PowerPC NLM changed. Define OLDFORMAT to get the
29 #include "nlm/ppc-ext.h"
30 #define Nlm_External_Fixed_Header Nlm32_powerpc_External_Fixed_Header
35 static bfd_boolean nlm_powerpc_backend_object_p
37 static bfd_boolean nlm_powerpc_write_prefix
41 static bfd_boolean nlm_powerpc_read_reloc
42 PARAMS ((bfd
*, nlmNAME(symbol_type
) *, asection
**, arelent
*));
43 static bfd_boolean nlm_powerpc_mangle_relocs
44 PARAMS ((bfd
*, asection
*, PTR
, bfd_vma
, bfd_size_type
));
45 static bfd_boolean nlm_powerpc_read_import
46 PARAMS ((bfd
*, nlmNAME(symbol_type
) *));
49 static bfd_boolean nlm_powerpc_write_reloc
50 PARAMS ((bfd
*, asection
*, arelent
*, int));
53 static bfd_boolean nlm_powerpc_write_import
54 PARAMS ((bfd
*, asection
*, arelent
*));
55 static bfd_boolean nlm_powerpc_write_external
56 PARAMS ((bfd
*, bfd_size_type
, asymbol
*, struct reloc_and_sec
*));
59 static bfd_boolean nlm_powerpc_set_public_section
60 PARAMS ((bfd
*, nlmNAME(symbol_type
) *));
61 static bfd_vma nlm_powerpc_get_public_offset
62 PARAMS ((bfd
*, asymbol
*));
67 /* The prefix header is only used in the old format. */
69 /* PowerPC NLM's have a prefix header before the standard NLM. This
70 function reads it in, verifies the version, and seeks the bfd to
71 the location before the regular NLM header. */
74 nlm_powerpc_backend_object_p (abfd
)
77 struct nlm32_powerpc_external_prefix_header s
;
79 if (bfd_bread ((PTR
) &s
, (bfd_size_type
) sizeof s
, abfd
) != sizeof s
)
82 if (memcmp (s
.signature
, NLM32_POWERPC_SIGNATURE
, sizeof s
.signature
) != 0
83 || H_GET_32 (abfd
, s
.headerVersion
) != NLM32_POWERPC_HEADER_VERSION
)
89 /* Write out the prefix. */
92 nlm_powerpc_write_prefix (abfd
)
95 struct nlm32_powerpc_external_prefix_header s
;
97 memset (&s
, 0, sizeof s
);
98 memcpy (s
.signature
, NLM32_POWERPC_SIGNATURE
, sizeof s
.signature
);
99 H_PUT_32 (abfd
, NLM32_POWERPC_HEADER_VERSION
, s
.headerVersion
);
100 H_PUT_32 (abfd
, 0, s
.origins
);
102 /* FIXME: What should we do about the date? */
104 if (bfd_bwrite ((PTR
) &s
, (bfd_size_type
) sizeof s
, abfd
) != sizeof s
)
110 #endif /* OLDFORMAT */
114 /* There is only one type of reloc in a PowerPC NLM. */
116 static reloc_howto_type nlm_powerpc_howto
=
119 2, /* size (0 = byte, 1 = short, 2 = long) */
121 FALSE
, /* pc_relative */
123 complain_overflow_bitfield
, /* complain_on_overflow */
124 0, /* special_function */
126 TRUE
, /* partial_inplace */
127 0xffffffff, /* src_mask */
128 0xffffffff, /* dst_mask */
129 FALSE
); /* pcrel_offset */
131 /* Read a PowerPC NLM reloc. */
134 nlm_powerpc_read_reloc (abfd
, sym
, secp
, rel
)
136 nlmNAME(symbol_type
) *sym
;
144 if (bfd_bread (temp
, (bfd_size_type
) sizeof (temp
), abfd
) != sizeof (temp
))
147 val
= bfd_get_32 (abfd
, temp
);
149 /* The value is a word offset into either the code or data segment.
150 This is the location which needs to be adjusted.
152 The high bit is 0 if the value is an offset into the data
153 segment, or 1 if the value is an offset into the text segment.
155 If this is a relocation fixup rather than an imported symbol (the
156 sym argument is NULL), then the second most significant bit is 0
157 if the address of the data segment should be added to the
158 location addressed by the value, or 1 if the address of the text
159 segment should be added.
161 If this is an imported symbol, the second most significant bit is
162 not used and must be 0. */
164 if ((val
& NLM_HIBIT
) == 0)
165 name
= NLM_INITIALIZED_DATA_NAME
;
168 name
= NLM_CODE_NAME
;
171 *secp
= bfd_get_section_by_name (abfd
, name
);
175 if ((val
& (NLM_HIBIT
>> 1)) == 0)
176 name
= NLM_INITIALIZED_DATA_NAME
;
179 name
= NLM_CODE_NAME
;
180 val
&=~ (NLM_HIBIT
>> 1);
182 rel
->sym_ptr_ptr
= bfd_get_section_by_name (abfd
, name
)->symbol_ptr_ptr
;
185 rel
->howto
= &nlm_powerpc_howto
;
187 rel
->address
= val
<< 2;
193 #else /* OLDFORMAT */
195 /* This reloc handling is only applicable to the old format. */
197 /* How to process the various reloc types. PowerPC NLMs use XCOFF
198 reloc types, and I have just copied the XCOFF reloc table here. */
200 static reloc_howto_type nlm_powerpc_howto_table
[] =
202 /* Standard 32 bit relocation. */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
207 FALSE
, /* pc_relative */
209 complain_overflow_bitfield
, /* complain_on_overflow */
210 0, /* special_function */
212 TRUE
, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE
), /* pcrel_offset */
217 /* 32 bit relocation, but store negative value. */
220 -2, /* size (0 = byte, 1 = short, 2 = long) */
222 FALSE
, /* pc_relative */
224 complain_overflow_bitfield
, /* complain_on_overflow */
225 0, /* special_function */
227 TRUE
, /* partial_inplace */
228 0xffffffff, /* src_mask */
229 0xffffffff, /* dst_mask */
230 FALSE
), /* pcrel_offset */
232 /* 32 bit PC relative relocation. */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 TRUE
, /* pc_relative */
239 complain_overflow_signed
, /* complain_on_overflow */
240 0, /* special_function */
242 TRUE
, /* partial_inplace */
243 0xffffffff, /* src_mask */
244 0xffffffff, /* dst_mask */
245 FALSE
), /* pcrel_offset */
247 /* 16 bit TOC relative relocation. */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
252 FALSE
, /* pc_relative */
254 complain_overflow_signed
, /* complain_on_overflow */
255 0, /* special_function */
257 TRUE
, /* partial_inplace */
258 0xffff, /* src_mask */
259 0xffff, /* dst_mask */
260 FALSE
), /* pcrel_offset */
262 /* I don't really know what this is. */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
267 FALSE
, /* pc_relative */
269 complain_overflow_bitfield
, /* complain_on_overflow */
270 0, /* special_function */
272 TRUE
, /* partial_inplace */
273 0xffffffff, /* src_mask */
274 0xffffffff, /* dst_mask */
275 FALSE
), /* pcrel_offset */
277 /* External TOC relative symbol. */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE
, /* pc_relative */
284 complain_overflow_bitfield
, /* complain_on_overflow */
285 0, /* special_function */
287 TRUE
, /* partial_inplace */
288 0xffff, /* src_mask */
289 0xffff, /* dst_mask */
290 FALSE
), /* pcrel_offset */
292 /* Local TOC relative symbol. */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 FALSE
, /* pc_relative */
299 complain_overflow_bitfield
, /* complain_on_overflow */
300 0, /* special_function */
302 TRUE
, /* partial_inplace */
303 0xffff, /* src_mask */
304 0xffff, /* dst_mask */
305 FALSE
), /* pcrel_offset */
309 /* Non modifiable absolute branch. */
312 2, /* size (0 = byte, 1 = short, 2 = long) */
314 FALSE
, /* pc_relative */
316 complain_overflow_bitfield
, /* complain_on_overflow */
317 0, /* special_function */
319 TRUE
, /* partial_inplace */
320 0x3fffffc, /* src_mask */
321 0x3fffffc, /* dst_mask */
322 FALSE
), /* pcrel_offset */
326 /* Non modifiable relative branch. */
327 HOWTO (0xa, /* type */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
331 TRUE
, /* pc_relative */
333 complain_overflow_signed
, /* complain_on_overflow */
334 0, /* special_function */
336 TRUE
, /* partial_inplace */
337 0x3fffffc, /* src_mask */
338 0x3fffffc, /* dst_mask */
339 FALSE
), /* pcrel_offset */
344 HOWTO (0xc, /* type */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
348 FALSE
, /* pc_relative */
350 complain_overflow_bitfield
, /* complain_on_overflow */
351 0, /* special_function */
353 TRUE
, /* partial_inplace */
354 0xffff, /* src_mask */
355 0xffff, /* dst_mask */
356 FALSE
), /* pcrel_offset */
359 HOWTO (0xd, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 FALSE
, /* pc_relative */
365 complain_overflow_bitfield
, /* complain_on_overflow */
366 0, /* special_function */
368 TRUE
, /* partial_inplace */
369 0xffff, /* src_mask */
370 0xffff, /* dst_mask */
371 FALSE
), /* pcrel_offset */
375 /* Non-relocating reference. */
376 HOWTO (0xf, /* type */
378 2, /* size (0 = byte, 1 = short, 2 = long) */
380 FALSE
, /* pc_relative */
382 complain_overflow_bitfield
, /* complain_on_overflow */
383 0, /* special_function */
385 FALSE
, /* partial_inplace */
388 FALSE
), /* pcrel_offset */
393 /* TOC relative indirect load. */
394 HOWTO (0x12, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 FALSE
, /* pc_relative */
400 complain_overflow_bitfield
, /* complain_on_overflow */
401 0, /* special_function */
403 TRUE
, /* partial_inplace */
404 0xffff, /* src_mask */
405 0xffff, /* dst_mask */
406 FALSE
), /* pcrel_offset */
408 /* TOC relative load address. */
409 HOWTO (0x13, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_bitfield
, /* complain_on_overflow */
416 0, /* special_function */
418 TRUE
, /* partial_inplace */
419 0xffff, /* src_mask */
420 0xffff, /* dst_mask */
421 FALSE
), /* pcrel_offset */
423 /* Modifiable relative branch. */
424 HOWTO (0x14, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE
, /* pc_relative */
430 complain_overflow_bitfield
, /* complain_on_overflow */
431 0, /* special_function */
432 "R_RRTBI", /* name */
433 TRUE
, /* partial_inplace */
434 0xffffffff, /* src_mask */
435 0xffffffff, /* dst_mask */
436 FALSE
), /* pcrel_offset */
438 /* Modifiable absolute branch. */
439 HOWTO (0x15, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 FALSE
, /* pc_relative */
445 complain_overflow_bitfield
, /* complain_on_overflow */
446 0, /* special_function */
447 "R_RRTBA", /* name */
448 TRUE
, /* partial_inplace */
449 0xffffffff, /* src_mask */
450 0xffffffff, /* dst_mask */
451 FALSE
), /* pcrel_offset */
453 /* Modifiable call absolute indirect. */
454 HOWTO (0x16, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_bitfield
, /* complain_on_overflow */
461 0, /* special_function */
463 TRUE
, /* partial_inplace */
464 0xffff, /* src_mask */
465 0xffff, /* dst_mask */
466 FALSE
), /* pcrel_offset */
468 /* Modifiable call relative. */
469 HOWTO (0x17, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 FALSE
, /* pc_relative */
475 complain_overflow_bitfield
, /* complain_on_overflow */
476 0, /* special_function */
478 TRUE
, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 FALSE
), /* pcrel_offset */
483 /* Modifiable branch absolute. */
484 HOWTO (0x18, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 FALSE
, /* pc_relative */
490 complain_overflow_bitfield
, /* complain_on_overflow */
491 0, /* special_function */
493 TRUE
, /* partial_inplace */
494 0xffff, /* src_mask */
495 0xffff, /* dst_mask */
496 FALSE
), /* pcrel_offset */
498 /* Modifiable branch absolute. */
499 HOWTO (0x19, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_bitfield
, /* complain_on_overflow */
506 0, /* special_function */
508 TRUE
, /* partial_inplace */
509 0xffff, /* src_mask */
510 0xffff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* Modifiable branch relative. */
514 HOWTO (0x1a, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE
, /* pc_relative */
520 complain_overflow_signed
, /* complain_on_overflow */
521 0, /* special_function */
523 TRUE
, /* partial_inplace */
524 0xffff, /* src_mask */
525 0xffff, /* dst_mask */
526 FALSE
), /* pcrel_offset */
528 /* Modifiable branch absolute. */
529 HOWTO (0x1b, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 FALSE
, /* pc_relative */
535 complain_overflow_bitfield
, /* complain_on_overflow */
536 0, /* special_function */
538 TRUE
, /* partial_inplace */
539 0xffff, /* src_mask */
540 0xffff, /* dst_mask */
541 FALSE
) /* pcrel_offset */
544 #define HOWTO_COUNT (sizeof nlm_powerpc_howto_table \
545 / sizeof nlm_powerpc_howto_table[0])
547 /* Read a PowerPC NLM reloc. */
550 nlm_powerpc_read_reloc (abfd
, sym
, secp
, rel
)
552 nlmNAME(symbol_type
) *sym
;
556 struct nlm32_powerpc_external_reloc ext
;
558 unsigned long l_symndx
;
561 asection
*code_sec
, *data_sec
, *bss_sec
;
563 /* Read the reloc from the file. */
564 if (bfd_bread (&ext
, (bfd_size_type
) sizeof ext
, abfd
) != sizeof ext
)
567 /* Swap in the fields. */
568 l_vaddr
= H_GET_32 (abfd
, ext
.l_vaddr
);
569 l_symndx
= H_GET_32 (abfd
, ext
.l_symndx
);
570 l_rtype
= H_GET_16 (abfd
, ext
.l_rtype
);
571 l_rsecnm
= H_GET_16 (abfd
, ext
.l_rsecnm
);
573 /* Get the sections now, for convenience. */
574 code_sec
= bfd_get_section_by_name (abfd
, NLM_CODE_NAME
);
575 data_sec
= bfd_get_section_by_name (abfd
, NLM_INITIALIZED_DATA_NAME
);
576 bss_sec
= bfd_get_section_by_name (abfd
, NLM_UNINITIALIZED_DATA_NAME
);
578 /* Work out the arelent fields. */
581 /* This is an import. sym_ptr_ptr is filled in by
582 nlm_canonicalize_reloc. */
583 rel
->sym_ptr_ptr
= NULL
;
591 else if (l_symndx
== 1)
593 else if (l_symndx
== 2)
597 bfd_set_error (bfd_error_bad_value
);
601 rel
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
606 BFD_ASSERT ((l_rtype
& 0xff) < HOWTO_COUNT
);
608 rel
->howto
= nlm_powerpc_howto_table
+ (l_rtype
& 0xff);
610 BFD_ASSERT (rel
->howto
->name
!= NULL
611 && ((l_rtype
& 0x8000) != 0
612 ? (rel
->howto
->complain_on_overflow
613 == complain_overflow_signed
)
614 : (rel
->howto
->complain_on_overflow
615 == complain_overflow_bitfield
))
616 && ((l_rtype
>> 8) & 0x1f) == rel
->howto
->bitsize
- 1);
620 else if (l_rsecnm
== 1)
623 l_vaddr
-= bfd_section_size (abfd
, code_sec
);
627 bfd_set_error (bfd_error_bad_value
);
631 rel
->address
= l_vaddr
;
636 #endif /* OLDFORMAT */
638 /* Mangle PowerPC NLM relocs for output. */
641 nlm_powerpc_mangle_relocs (abfd
, sec
, data
, offset
, count
)
642 bfd
*abfd ATTRIBUTE_UNUSED
;
643 asection
*sec ATTRIBUTE_UNUSED
;
644 PTR data ATTRIBUTE_UNUSED
;
645 bfd_vma offset ATTRIBUTE_UNUSED
;
646 bfd_size_type count ATTRIBUTE_UNUSED
;
651 /* Read a PowerPC NLM import record */
654 nlm_powerpc_read_import (abfd
, sym
)
656 nlmNAME(symbol_type
) *sym
;
658 struct nlm_relent
*nlm_relocs
; /* relocation records for symbol */
659 bfd_size_type rcount
; /* number of relocs */
660 bfd_byte temp
[NLM_TARGET_LONG_SIZE
]; /* temporary 32-bit value */
661 unsigned char symlength
; /* length of symbol name */
664 if (bfd_bread ((PTR
) &symlength
, (bfd_size_type
) sizeof (symlength
), abfd
)
665 != sizeof (symlength
))
667 sym
-> symbol
.the_bfd
= abfd
;
668 name
= bfd_alloc (abfd
, (bfd_size_type
) symlength
+ 1);
671 if (bfd_bread (name
, (bfd_size_type
) symlength
, abfd
) != symlength
)
673 name
[symlength
] = '\0';
674 sym
-> symbol
.name
= name
;
675 sym
-> symbol
.flags
= 0;
676 sym
-> symbol
.value
= 0;
677 sym
-> symbol
.section
= bfd_und_section_ptr
;
678 if (bfd_bread ((PTR
) temp
, (bfd_size_type
) sizeof (temp
), abfd
)
681 rcount
= H_GET_32 (abfd
, temp
);
682 nlm_relocs
= ((struct nlm_relent
*)
683 bfd_alloc (abfd
, rcount
* sizeof (struct nlm_relent
)));
684 if (nlm_relocs
== (struct nlm_relent
*) NULL
)
686 sym
-> relocs
= nlm_relocs
;
688 while (sym
-> rcnt
< rcount
)
692 if (! nlm_powerpc_read_reloc (abfd
, sym
, §ion
, &nlm_relocs
-> reloc
))
694 nlm_relocs
-> section
= section
;
703 /* Write a PowerPC NLM reloc. */
706 nlm_powerpc_write_import (abfd
, sec
, rel
)
715 /* PowerPC NetWare only supports one kind of reloc. */
717 || rel
->howto
== NULL
718 || rel
->howto
->rightshift
!= 0
719 || rel
->howto
->size
!= 2
720 || rel
->howto
->bitsize
!= 32
721 || rel
->howto
->bitpos
!= 0
722 || rel
->howto
->pc_relative
723 || (rel
->howto
->src_mask
!= 0xffffffff && rel
->addend
!= 0)
724 || rel
->howto
->dst_mask
!= 0xffffffff)
726 bfd_set_error (bfd_error_invalid_operation
);
730 sym
= *rel
->sym_ptr_ptr
;
732 /* The value we write out is the offset into the appropriate
733 segment, rightshifted by two. This offset is the section vma,
734 adjusted by the vma of the lowest section in that segment, plus
735 the address of the relocation. */
736 val
= bfd_get_section_vma (abfd
, sec
) + rel
->address
;
739 bfd_set_error (bfd_error_bad_value
);
744 /* The high bit is 0 if the reloc is in the data section, or 1 if
745 the reloc is in the code section. */
746 if (bfd_get_section_flags (abfd
, sec
) & SEC_DATA
)
747 val
-= nlm_get_data_low (abfd
);
750 val
-= nlm_get_text_low (abfd
);
754 if (! bfd_is_und_section (bfd_get_section (sym
)))
756 /* This is an internal relocation fixup. The second most
757 significant bit is 0 if this is a reloc against the data
758 segment, or 1 if it is a reloc against the text segment. */
759 if (bfd_get_section_flags (abfd
, bfd_get_section (sym
)) & SEC_CODE
)
760 val
|= NLM_HIBIT
>> 1;
763 bfd_put_32 (abfd
, val
, temp
);
764 if (bfd_bwrite (temp
, (bfd_size_type
) sizeof (temp
), abfd
) != sizeof (temp
))
770 #else /* OLDFORMAT */
772 /* This is used for the reloc handling in the old format. */
774 /* Write a PowerPC NLM reloc. */
777 nlm_powerpc_write_reloc (abfd
, sec
, rel
, indx
)
783 struct nlm32_powerpc_external_reloc ext
;
784 asection
*code_sec
, *data_sec
, *bss_sec
;
787 unsigned long l_symndx
;
790 reloc_howto_type
*howto
;
791 bfd_size_type address
;
793 /* Get the sections now, for convenience. */
794 code_sec
= bfd_get_section_by_name (abfd
, NLM_CODE_NAME
);
795 data_sec
= bfd_get_section_by_name (abfd
, NLM_INITIALIZED_DATA_NAME
);
796 bss_sec
= bfd_get_section_by_name (abfd
, NLM_UNINITIALIZED_DATA_NAME
);
798 sym
= *rel
->sym_ptr_ptr
;
799 symsec
= bfd_get_section (sym
);
802 BFD_ASSERT (bfd_is_und_section (symsec
));
807 if (symsec
== code_sec
)
809 else if (symsec
== data_sec
)
811 else if (symsec
== bss_sec
)
815 bfd_set_error (bfd_error_bad_value
);
820 H_PUT_32 (abfd
, l_symndx
, ext
.l_symndx
);
822 for (howto
= nlm_powerpc_howto_table
;
823 howto
< nlm_powerpc_howto_table
+ HOWTO_COUNT
;
826 if (howto
->rightshift
== rel
->howto
->rightshift
827 && howto
->size
== rel
->howto
->size
828 && howto
->bitsize
== rel
->howto
->bitsize
829 && howto
->pc_relative
== rel
->howto
->pc_relative
830 && howto
->bitpos
== rel
->howto
->bitpos
831 && (howto
->partial_inplace
== rel
->howto
->partial_inplace
832 || (! rel
->howto
->partial_inplace
833 && rel
->addend
== 0))
834 && (howto
->src_mask
== rel
->howto
->src_mask
835 || (rel
->howto
->src_mask
== 0
836 && rel
->addend
== 0))
837 && howto
->dst_mask
== rel
->howto
->dst_mask
838 && howto
->pcrel_offset
== rel
->howto
->pcrel_offset
)
841 if (howto
>= nlm_powerpc_howto_table
+ HOWTO_COUNT
)
843 bfd_set_error (bfd_error_bad_value
);
847 l_rtype
= howto
->type
;
848 if (howto
->complain_on_overflow
== complain_overflow_signed
)
850 l_rtype
|= (howto
->bitsize
- 1) << 8;
851 H_PUT_16 (abfd
, l_rtype
, ext
.l_rtype
);
853 address
= rel
->address
;
857 else if (sec
== data_sec
)
860 address
+= bfd_section_size (abfd
, code_sec
);
864 bfd_set_error (bfd_error_bad_value
);
868 H_PUT_16 (abfd
, l_rsecnm
, ext
.l_rsecnm
);
869 H_PUT_32 (abfd
, address
, ext
.l_vaddr
);
871 if (bfd_bwrite (&ext
, (bfd_size_type
) sizeof ext
, abfd
) != sizeof ext
)
877 /* Write a PowerPC NLM import. */
880 nlm_powerpc_write_import (abfd
, sec
, rel
)
885 return nlm_powerpc_write_reloc (abfd
, sec
, rel
, -1);
888 #endif /* OLDFORMAT */
890 /* Write a PowerPC NLM external symbol. This routine keeps a static
891 count of the symbol index. FIXME: I don't know if this is
892 necessary, and the index never gets reset. */
895 nlm_powerpc_write_external (abfd
, count
, sym
, relocs
)
899 struct reloc_and_sec
*relocs
;
903 unsigned char temp
[NLM_TARGET_LONG_SIZE
];
908 len
= strlen (sym
->name
);
909 if ((bfd_bwrite (&len
, (bfd_size_type
) sizeof (bfd_byte
), abfd
)
910 != sizeof (bfd_byte
))
911 || bfd_bwrite (sym
->name
, (bfd_size_type
) len
, abfd
) != len
)
914 bfd_put_32 (abfd
, count
, temp
);
915 if (bfd_bwrite (temp
, (bfd_size_type
) sizeof (temp
), abfd
) != sizeof (temp
))
918 for (i
= 0; i
< count
; i
++)
921 if (! nlm_powerpc_write_import (abfd
, relocs
[i
].sec
, relocs
[i
].rel
))
924 if (! nlm_powerpc_write_reloc (abfd
, relocs
[i
].sec
,
925 relocs
[i
].rel
, indx
))
939 /* PowerPC Netware uses a word offset, not a byte offset, for public
942 /* Set the section for a public symbol. */
945 nlm_powerpc_set_public_section (abfd
, sym
)
947 nlmNAME(symbol_type
) *sym
;
949 if (sym
->symbol
.value
& NLM_HIBIT
)
951 sym
->symbol
.value
&= ~NLM_HIBIT
;
952 sym
->symbol
.flags
|= BSF_FUNCTION
;
953 sym
->symbol
.section
=
954 bfd_get_section_by_name (abfd
, NLM_CODE_NAME
);
958 sym
->symbol
.section
=
959 bfd_get_section_by_name (abfd
, NLM_INITIALIZED_DATA_NAME
);
962 sym
->symbol
.value
<<= 2;
967 /* Get the offset to write out for a public symbol. */
970 nlm_powerpc_get_public_offset (abfd
, sym
)
977 offset
= bfd_asymbol_value (sym
);
978 sec
= bfd_get_section (sym
);
979 if (sec
->flags
& SEC_CODE
)
981 offset
-= nlm_get_text_low (abfd
);
984 else if (sec
->flags
& (SEC_DATA
| SEC_ALLOC
))
986 /* SEC_ALLOC is for the .bss section. */
987 offset
-= nlm_get_data_low (abfd
);
991 /* We can't handle an exported symbol that is not in the code or
993 bfd_set_error (bfd_error_invalid_operation
);
994 /* FIXME: No way to return error. */
1001 #endif /* ! defined (OLDFORMAT) */
1003 #include "nlmswap.h"
1005 static const struct nlm_backend_data nlm32_powerpc_backend
=
1007 "NetWare PowerPC Module \032",
1008 sizeof (Nlm32_powerpc_External_Fixed_Header
),
1010 0, /* optional_prefix_size */
1012 sizeof (struct nlm32_powerpc_external_prefix_header
),
1018 0, /* backend_object_p */
1019 0, /* write_prefix */
1021 nlm_powerpc_backend_object_p
,
1022 nlm_powerpc_write_prefix
,
1024 nlm_powerpc_read_reloc
,
1025 nlm_powerpc_mangle_relocs
,
1026 nlm_powerpc_read_import
,
1027 nlm_powerpc_write_import
,
1029 nlm_powerpc_set_public_section
,
1030 nlm_powerpc_get_public_offset
,
1032 0, /* set_public_section */
1033 0, /* get_public_offset */
1035 nlm_swap_fixed_header_in
,
1036 nlm_swap_fixed_header_out
,
1037 nlm_powerpc_write_external
,
1038 0, /* write_export */
1041 #define TARGET_BIG_NAME "nlm32-powerpc"
1042 #define TARGET_BIG_SYM nlmNAME(powerpc_vec)
1043 #define TARGET_BACKEND_DATA &nlm32_powerpc_backend
1045 #include "nlm-target.h"