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