• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9CC=${CC:=gcc}
10LD=${LD:=ld}
11
12TST_CNT=5
13TST_TESTFUNC=test
14TST_SETUP=setup
15TST_NEEDS_TMPDIR=1
16TST_NEEDS_CMDS="$CC $LD"
17
18setup()
19{
20	for i in rf1 f1 rd1 d1 main; do
21		ROD $CC -fPIC -c -o ${i}.o $TST_DATAROOT/${i}.c
22	done
23}
24
25test1()
26{
27	EXPECT_FAIL $LD x.o y.o 2\> ld.out
28
29	if grep -q "[xy]\.o.*No such file or directory" ld.out; then
30		tst_res TPASS "Missing files were reported"
31	else
32		tst_res TFAIL "Missing files were not reported"
33		cat ld.out
34	fi
35}
36
37test2()
38{
39	EXPECT_FAIL $CC x.o y.o 2\> cc.out
40
41	if grep -q "[xy]\.o.*No such file or directory" cc.out; then
42		tst_res TPASS "Missing files were reported"
43	else
44		tst_res TFAIL "Missing files were not reported"
45		cat cc.out
46	fi
47}
48
49test3()
50{
51	EXPECT_PASS $LD -shared f1.o d1.o -o test.so
52
53	if file test.so |grep -q -e 'pie executable' -e 'shared object'; then
54		tst_res TPASS "Shared library could be build"
55	else
56		tst_res TFAIL "Failed to build shared library"
57	fi
58}
59
60test4()
61{
62	EXPECT_PASS $LD -Bdynamic -shared f1.o d1.o -o test.so
63	EXPECT_FAIL $LD -Bstatic -L. main.o rd1.o test.so -o a.out
64}
65
66test5()
67{
68	EXPECT_PASS $LD -Bdynamic -shared main.o f1.o rf1.o -o test.so -L/usr/lib/
69	EXPECT_FAIL $LD -Bstatic -r main.o f1.o rf1.o test.so -L/usr/lib/ 2\> ld.out
70	cat ld.out
71
72	if grep -q "$LD: attempted static link of dynamic object" ld.out; then
73		tst_res TPASS "Got expected error message"
74	else
75		tst_res TFAIL "Unexpected error message"
76		cat ld.out
77	fi
78}
79
80. tst_test.sh
81tst_run
82