]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-elf/sec-to-seg.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / sec-to-seg.exp
CommitLineData
2e658c87
NC
1# Test the assigment of sections to segments.
2#
250d07de 3# Copyright (C) 2008-2021 Free Software Foundation, Inc.
2e658c87
NC
4# Contributed by Red Hat.
5#
6# This file is part of the GNU Binutils.
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
21# MA 02110-1301, USA.
22
23set testname "assignment of ELF sections to segments"
24
25if {! [is_elf_format] } {
26 unsupported $testname
27 return
28}
29
30if { ! [ld_assemble $as $srcdir/$subdir/sec-to-seg1.s tmpdir/sec-to-seg1.o]
31 || ! [ld_assemble $as $srcdir/$subdir/sec-to-seg2.s tmpdir/sec-to-seg2.o]} then {
32 unresolved $testname
33 return
34}
35
36proc sec_to_seg_test { testname scriptname same_seg } {
37 global srcdir
38 global subdir
39 global ld
40 global exec_output
41 global READELF
42
d9816402 43 if {! [ld_link $ld tmpdir/sec-to-seg "-T $srcdir/$subdir/$scriptname tmpdir/sec-to-seg1.o tmpdir/sec-to-seg2.o"] } then {
2e658c87
NC
44 fail $testname
45 return 0
46 }
47
48 send_log "$READELF --program-headers --section-headers tmpdir/sec-to-seg\n"
49 set exec_output [run_host_cmd "$READELF" "--program-headers --section-headers tmpdir/sec-to-seg"]
50
51 if { $same_seg == 1 } {
52 if {! [regexp ".*.sec1 .sec2" $exec_output] } {
53 fail $testname
54 return 0
55 }
56 } else {
57 if { [regexp ".*.sec1 .sec2" $exec_output] } {
58 fail $testname
59 return 0
60 }
61 }
62
63 pass $testname
64 return 1
65}
66
67# Assuming a pagesize of 0x1000 then:
68#
69# Test Sec1 End Sec 2 Start Expected Result
70# ---- -------- ----------- ---------------
71# A 00001042 00001043 Both sections on same page: assign to same segment.
72# B 00001042 00002044 Sections on adjacent pages: assign to same segment.
73# C 00001042 00003044 Sections on disjoint pages: assign to separate segments.
74
75# These targets have a pagesize of 1, so they will always end up
76# placing the two sections in separate segments in the B test.
77if { [istarget avr-*-*]
78 || [istarget cr16-*-*]
79 || [istarget crx-*-*]
80 || [istarget dlx-*-*]
d1f70bdc 81 || [istarget ft32-*-*]
2e658c87
NC
82 || [istarget h8300-*-*]
83 || [istarget ip2k-*-*]
84 || [istarget m32r-*-*]
47f92981 85 || [istarget moxie-*-*]
2e658c87 86 || [istarget msp430-*-*]
47f92981 87 || [istarget mt-*-*]
0220170b 88 || [istarget pru-*-*]
c18392d8 89 || [istarget visium-*-*]
2e658c87
NC
90 } {
91 set B_test_same_seg 0
92} else {
93 set B_test_same_seg 1
94}
95
96sec_to_seg_test "assignment of ELF sections to segments (same page)" "sec-to-seg-script-same-page.t" 1
97sec_to_seg_test "assignment of ELF sections to segments (adjacent pages)" "sec-to-seg-script-adjoining-pages.t" $B_test_same_seg
98sec_to_seg_test "assignment of ELF sections to segments (disjoint pages)" "sec-to-seg-script-disjoint-pages.t" 0
99
100
101# FIXME: Add more tests to check other rules of section to segment assignment.