ld01.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) International Business Machines Corp., 2000
  4. # Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  5. # Author: Robbie Williamson <robbiew@us.ibm.com>
  6. #
  7. # Test basic functionality of the `ld` command.
  8. CC=${CC:=gcc}
  9. LD=${LD:=ld}
  10. TST_CNT=5
  11. TST_TESTFUNC=test
  12. TST_SETUP=setup
  13. TST_NEEDS_TMPDIR=1
  14. TST_NEEDS_CMDS="$CC $LD"
  15. . tst_test.sh
  16. setup()
  17. {
  18. for i in rf1 f1 rd1 d1 main; do
  19. ROD $CC -fPIC -c -o ${i}.o $TST_DATAROOT/${i}.c
  20. done
  21. }
  22. test1()
  23. {
  24. EXPECT_FAIL $LD x.o y.o 2\> ld.out
  25. if grep -q "$LD:.*[xy]\.o.*No such file or directory" ld.out; then
  26. tst_res TPASS "Missing files were reported"
  27. else
  28. tst_res TFAIL "Missing files were not reported"
  29. cat ld.out
  30. fi
  31. }
  32. test2()
  33. {
  34. EXPECT_FAIL $CC x.o y.o 2\> cc.out
  35. if grep -q "$CC:.*[xy]\.o.*No such file or directory" cc.out; then
  36. tst_res TPASS "Missing files were reported"
  37. else
  38. tst_res TFAIL "Missing files were not reported"
  39. cat cc.out
  40. fi
  41. }
  42. test3()
  43. {
  44. EXPECT_PASS $LD -shared f1.o d1.o -o test.so
  45. if file test.so |grep -q -e 'pie executable' -e 'shared object'; then
  46. tst_res TPASS "Shared library could be build"
  47. else
  48. tst_res TFAIL "Failed to build shared library"
  49. fi
  50. }
  51. test4()
  52. {
  53. EXPECT_PASS $LD -Bdynamic -shared f1.o d1.o -o test.so
  54. EXPECT_FAIL $LD -Bstatic -L. main.o rd1.o test.so -o a.out
  55. }
  56. test5()
  57. {
  58. EXPECT_PASS $LD -Bdynamic -shared main.o f1.o rf1.o -o test.so -L/usr/lib/
  59. EXPECT_FAIL $LD -Bstatic -r main.o f1.o rf1.o test.so -L/usr/lib/ 2\> ld.out
  60. cat ld.out
  61. if grep -q "$LD: attempted static link of dynamic object" ld.out; then
  62. tst_res TPASS "Got expected error message"
  63. else
  64. tst_res TFAIL "Unexpected error message"
  65. cat ld.out
  66. fi
  67. }
  68. tst_run