phdrs.exp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Test PHDRS in a linker script.
  2. # By Ian Lance Taylor, Cygnus Support.
  3. # Copyright (C) 1999-2022 Free Software Foundation, Inc.
  4. #
  5. # This file is part of the GNU Binutils.
  6. #
  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.
  11. #
  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.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  20. # MA 02110-1301, USA.
  21. # PHDRS is only meaningful for ELF.
  22. if ![is_elf_format] {
  23. return
  24. }
  25. # This is a very simplistic test.
  26. set testname "PHDRS"
  27. set ldopt ""
  28. if { [istarget spu*-*-*] } {
  29. set ldopt "--local-store 0:0"
  30. }
  31. if ![ld_assemble $as $srcdir/$subdir/phdrs.s tmpdir/phdrs.o] {
  32. unsupported $testname
  33. return
  34. }
  35. set phdrs_regexp \
  36. ".*Program Header:.*PHDR *off *0x00*34 *vaddr *0x00*800034 *paddr *0x00*800034.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*800000 *paddr *0x00*800000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
  37. # On a 64 bit ELF format, we need different numbers.
  38. if [is_elf64 tmpdir/phdrs.o] {
  39. set phdrs_regexp \
  40. ".*Program Header:.*PHDR *off *0x00*40 *vaddr *0x00*800040 *paddr *0x00*800040.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*800000 *paddr *0x00*800000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
  41. }
  42. set ldopt "$ldopt -T $srcdir/$subdir/phdrs.t tmpdir/phdrs.o"
  43. if ![ld_link $ld tmpdir/phdrs $ldopt] {
  44. fail $testname
  45. } else {
  46. set exec_output [run_host_cmd "$objdump" "--private-headers tmpdir/phdrs"]
  47. set exec_output [prune_warnings $exec_output]
  48. verbose -log $exec_output
  49. if [regexp $phdrs_regexp $exec_output] {
  50. pass $testname
  51. } else {
  52. fail $testname
  53. }
  54. }