| 1 | /* ldwrite.c -- write out the linked file
|
|---|
| 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000
|
|---|
| 3 | Free Software Foundation, Inc.
|
|---|
| 4 | Written by Steve Chamberlain [email protected]
|
|---|
| 5 |
|
|---|
| 6 | This file is part of GLD, the Gnu Linker.
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program; if not, write to the Free Software
|
|---|
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | #include "bfd.h"
|
|---|
| 23 | #include "sysdep.h"
|
|---|
| 24 | #include "bfdlink.h"
|
|---|
| 25 | #include "libiberty.h"
|
|---|
| 26 |
|
|---|
| 27 | #include "ld.h"
|
|---|
| 28 | #include "ldexp.h"
|
|---|
| 29 | #include "ldlang.h"
|
|---|
| 30 | #include "ldwrite.h"
|
|---|
| 31 | #include "ldmisc.h"
|
|---|
| 32 | #include "ldgram.h"
|
|---|
| 33 | #include "ldmain.h"
|
|---|
| 34 |
|
|---|
| 35 | static void build_link_order PARAMS ((lang_statement_union_type *));
|
|---|
| 36 | static asection *clone_section PARAMS ((bfd *, asection *, const char *, int *));
|
|---|
| 37 | static void split_sections PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 38 |
|
|---|
| 39 | /* Build link_order structures for the BFD linker. */
|
|---|
| 40 |
|
|---|
| 41 | static void
|
|---|
| 42 | build_link_order (statement)
|
|---|
| 43 | lang_statement_union_type *statement;
|
|---|
| 44 | {
|
|---|
| 45 | switch (statement->header.type)
|
|---|
| 46 | {
|
|---|
| 47 | case lang_data_statement_enum:
|
|---|
| 48 | {
|
|---|
| 49 | asection *output_section;
|
|---|
| 50 | struct bfd_link_order *link_order;
|
|---|
| 51 | bfd_vma value;
|
|---|
| 52 | boolean big_endian = false;
|
|---|
| 53 |
|
|---|
| 54 | output_section = statement->data_statement.output_section;
|
|---|
| 55 | ASSERT (output_section->owner == output_bfd);
|
|---|
| 56 |
|
|---|
| 57 | link_order = bfd_new_link_order (output_bfd, output_section);
|
|---|
| 58 | if (link_order == NULL)
|
|---|
| 59 | einfo (_("%P%F: bfd_new_link_order failed\n"));
|
|---|
| 60 |
|
|---|
| 61 | link_order->type = bfd_data_link_order;
|
|---|
| 62 | link_order->offset = statement->data_statement.output_vma;
|
|---|
| 63 | link_order->u.data.contents = (bfd_byte *) xmalloc (QUAD_SIZE);
|
|---|
| 64 |
|
|---|
| 65 | value = statement->data_statement.value;
|
|---|
| 66 |
|
|---|
| 67 | /* If the endianness of the output BFD is not known, then we
|
|---|
| 68 | base the endianness of the data on the first input file.
|
|---|
| 69 | By convention, the bfd_put routines for an unknown
|
|---|
| 70 | endianness are big endian, so we must swap here if the
|
|---|
| 71 | input file is little endian. */
|
|---|
| 72 | if (bfd_big_endian (output_bfd))
|
|---|
| 73 | big_endian = true;
|
|---|
| 74 | else if (bfd_little_endian (output_bfd))
|
|---|
| 75 | big_endian = false;
|
|---|
| 76 | else
|
|---|
| 77 | {
|
|---|
| 78 | boolean swap;
|
|---|
| 79 |
|
|---|
| 80 | swap = false;
|
|---|
| 81 | if (command_line.endian == ENDIAN_BIG)
|
|---|
| 82 | big_endian = true;
|
|---|
| 83 | else if (command_line.endian == ENDIAN_LITTLE)
|
|---|
|
|---|