xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
1# Copyright 2018-2024 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# This file is part of the gdb testsuite
17
18#
19# PR gdb/21695
20# This tests if gdb can display line information of relocated symbols in the
21# case where executable text section was at address zero before relocation.
22#
23
24standard_testfile .c
25
26# Build executable with stripped startup code and text section starting at zero
27
28set opts {}
29lappend opts debug
30lappend opts "ldflags=-nostdlib -emain -Wl,-Ttext=0x00 -Wl,-N"
31lappend opts additional_flags=-static
32
33set ld_flags ldflags=-Wl,--no-warn-rwx-segments
34if { [gdb_can_simple_compile ld-flags {int main () { return 0; }} executable \
35	  $ld_flags] } {
36    lappend opts $ld_flags
37}
38
39if {[build_executable $testfile.exp $testfile $srcfile $opts] == -1} {
40    untested "failed to compile"
41    return -1
42}
43
44clean_restart
45
46# Load symbols at an offset 0xffff0000 using add-symbol-file
47
48gdb_test "add-symbol-file $binfile 0xffff0000" \
49    "Reading symbols from .*" \
50    "add-symbol-file" \
51    "add symbol table from file \".*\" at.*\\(y or n\\) " "y"
52
53# Check if we are able to read offset adjusted line information of main
54
55gdb_test "info line main" \
56	"Line.*starts at address 0xffff0000.*and ends at.*"
57