Updated Malay translation for the bfd sub-directory
[binutils-gdb.git] / ld / emultempl / loongarchelf.em
blobde64b1d30de92fa66e65d817118996886a159afc
1 # This shell script emits a C file. -*- C -*-
2 #   Copyright (C) 2021-2025 Free Software Foundation, Inc.
3 #   Contributed by Loongson Ltd.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; see the file COPYING3. If not,
19 # see <http://www.gnu.org/licenses/>.
21 fragment <<EOF
23 #include "ldmain.h"
24 #include "ldctor.h"
25 #include "elf/loongarch.h"
26 #include "elfxx-loongarch.h"
28 EOF
30 # Disable linker relaxation if set address of section or segment.
31 PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
32     case OPTION_SECTION_START:
33     case OPTION_TTEXT:
34     case OPTION_TBSS:
35     case OPTION_TDATA:
36     case OPTION_TTEXT_SEGMENT:
37     case OPTION_TRODATA_SEGMENT:
38     case OPTION_TLDATA_SEGMENT:
39       link_info.disable_target_specific_optimizations = 2;
40       return false;
43 fragment <<EOF
44 static void
45 larch_elf_before_allocation (void)
47   gld${EMULATION_NAME}_before_allocation ();
49   if (link_info.discard == discard_sec_merge)
50     link_info.discard = discard_l;
52   if (!bfd_link_relocatable (&link_info))
53     {
54       /* We always need at least some relaxation to handle code alignment.  */
55       if (RELAXATION_DISABLED_BY_USER)
56         TARGET_ENABLE_RELAXATION;
57       else
58         ENABLE_RELAXATION;
59     }
61   link_info.relax_pass = 2;
64 static void
65 gld${EMULATION_NAME}_after_allocation (void)
67   int need_layout = 0;
69   /* Don't attempt to discard unused .eh_frame sections until the final link,
70      as we can't reliably tell if they're used until after relaxation.  */
71   if (!bfd_link_relocatable (&link_info))
72     {
73       need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
74       if (need_layout < 0)
75         {
76           einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
77           return;
78         }
79     }
81   /* The program header size of executable file may increase.  */
82   if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
83       && !bfd_link_relocatable (&link_info))
84     {
85       if (lang_phdr_list == NULL)
86         elf_seg_map (link_info.output_bfd) = NULL;
87       if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd,
88                                               &link_info,
89                                               NULL))
90         einfo (_("%F%P: map sections to segments failed: %E\n"));
91     }
93   /* Adjust program header size and .eh_frame_hdr size before
94      lang_relax_sections. Without it, the vma of data segment may increase.  */
95   lang_do_assignments (lang_allocating_phase_enum);
96   lang_reset_memory_regions ();
97   lang_size_sections (NULL, true);
99   enum phase_enum *phase = &(expld.dataseg.phase);
100   bfd_elf${ELFSIZE}_loongarch_set_data_segment_info (&link_info, (int *) phase);
101   /* gld${EMULATION_NAME}_map_segments (need_layout); */
102   ldelf_map_segments (need_layout);
107 LDEMUL_BEFORE_ALLOCATION=larch_elf_before_allocation
108 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation