aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.3.3/fedora/gcc43-ppc32-retaddr.patch
blob: e9ae1bc303312a35ca69044d325c26c938789f03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
2005-11-28  Jakub Jelinek  <jakub@redhat.com>

	* config/rs6000/rs6000.c (rs6000_return_addr): If COUNT == 0,
	read word RETURN_ADDRESS_OFFSET bytes above arg_pointer_rtx
	instead of doing an extran indirection from frame_pointer_rtx.

	* gcc.dg/20051128-1.c: New test.

--- gcc/config/rs6000/rs6000.c.jj	2005-11-26 14:38:01.000000000 +0100
+++ gcc/config/rs6000/rs6000.c	2005-11-28 20:32:18.000000000 +0100
@@ -13166,17 +13166,22 @@ rs6000_return_addr (int count, rtx frame
      don't try to be too clever here.  */
   if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
     {
+      rtx x;
       cfun->machine->ra_needs_full_frame = 1;
 
-      return
-	gen_rtx_MEM
-	  (Pmode,
-	   memory_address
-	   (Pmode,
-	    plus_constant (copy_to_reg
-			   (gen_rtx_MEM (Pmode,
-					 memory_address (Pmode, frame))),
-			   RETURN_ADDRESS_OFFSET)));
+      if (count == 0)
+	{
+	  gcc_assert (frame == frame_pointer_rtx);
+	  x = arg_pointer_rtx;
+	}
+      else
+	{
+	  x = memory_address (Pmode, frame);
+	  x = copy_to_reg (gen_rtx_MEM (Pmode, x));
+	}
+
+      x = plus_constant (x, RETURN_ADDRESS_OFFSET);
+      return gen_rtx_MEM (Pmode, memory_address (Pmode, x));
     }
 
   cfun->machine->ra_need_lr = 1;
--- gcc/testsuite/gcc.dg/20051128-1.c.jj	2005-10-10 11:21:41.096999000 +0200
+++ gcc/testsuite/gcc.dg/20051128-1.c	2005-11-28 12:30:57.000000000 +0100
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -fpic" } */
+
+extern void exit (int);
+extern void abort (void);
+
+int b;
+
+struct A
+{
+  void *pad[147];
+  void *ra, *h;
+  long o;
+};
+
+void
+__attribute__((noinline))
+foo (struct A *a, void *x)
+{
+  __builtin_memset (a, 0, sizeof (a));
+  if (!b)
+    exit (0);
+}
+
+void
+__attribute__((noinline))
+bar (void)
+{
+  struct A a;
+
+  __builtin_unwind_init ();
+  foo (&a, __builtin_return_address (0));
+}
+
+int
+main (void)
+{
+  bar ();
+  abort ();
+  return 0;
+}
Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/bin/bash
# Common function for test
# Expect should be installed for SSH Testing
# To execute `runqemu`, NOPASSWD needs to be set in /etc/sudoers for user
# For example, for user "builder", /etc/sudoers can be like following:
# #########
# #Members of the admin group may gain root privileges
# %builder ALL=(ALL) NOPASSWD: NOPASSWD: ALL
# #########
#
# Author: Jiajun Xu <jiajun.xu@intel.com>
#
# This file is licensed under the GNU General Public License,
# Version 2.
#

TYPE="ext3"

# The folder to hold all scripts running on targets
TOOLS="$POKYBASE/scripts/qemuimage-tests/tools"

# Test Directory on target for testing
TARGET_TEST_DIR="/opt/test"

# Global variable for process id
PID=0

# Global variable for target ip address
TARGET_IPADDR=0

# common function for information print
Test_Error()
{
	echo -e "\tTest_Error: $*"
}

Test_Info()
{
	echo -e "\tTest_Info: $*"
}

# function to copy files from host into target
# $1 is the ip address of target
# $2 is the files, which need to be copied into target
# $3 is the path on target, where files are copied into
Test_SCP()
{
	local ip_addr=$1
	local src=$2
	local des=$3
	local tmpfile=`mktemp`
	local timeout=60
	local ret=0

	# We use expect to interactive with target by ssh
	local exp_cmd=`cat << EOF
eval spawn scp -o UserKnownHostsFile=$tmpfile "$src" root@$ip_addr:"$des"
set timeout $time_out
expect {
    "*assword:" { send "\r"; exp_continue}
    "*(yes/no)?" { send "yes\r"; exp_continue }
    eof          { exit [ lindex [wait] 3 ] }
}
EOF`
	expect -c "$exp_cmd"
	ret=$?
	rm -rf $tmpfile
	return $ret
}

# function to run command in $ip_addr via ssh
Test_SSH()
{
	local ip_addr=$1
	shift
	local command=$@
	local tmpfile=`mktemp`
	local timeout=60
	local ret=0
	local exp_cmd=`cat << EOF
eval spawn ssh -o UserKnownHostsFile=$tmpfile root@$ip_addr "$command"
set timeout $time_out
expect {
    "*assword:" { send "\r"; exp_continue}
    "*(yes/no)?" { send "yes\r"; exp_continue }
    eof          { exit [ lindex [wait] 3 ] }
}
EOF`
	expect -c "$exp_cmd"
	ret=$?
	rm -rf $tmpfile
	return $ret
}

# function to check if ssh is up in $ip_addr
Test_SSH_UP()
{
	local ip_addr=$1
	local timeout=$2
	local interval=0

	while [ ${interval} -lt ${timeout} ]
	do
		Test_SSH ${ip_addr} "hostname"
		if [ $? -ne 0 ]; then
			interval=`expr $interval + 10`
			sleep 10
		else
			Test_Info "We can ssh on ${ip_addr} now"
			return 0
		fi

	done

	Test_Info "We can not ssh on ${ip_addr} in ${timeout}"
	return 1
}

# function to prepare target test environment
# $1 is the ip address of target system
# $2 is the files, which needs to be copied into target
Test_Target_Pre()
{
	local ip_addr=$1
	local testscript=$2

	# Create a pre-defined folder for test scripts
	Test_SSH $ip_addr "mkdir -p $TARGET_TEST_DIR"
	if [ $? -eq 0 ]; then
		# Copy test scripts into target
		Test_SCP $ip_addr $testscript $TARGET_TEST_DIR && return 0
	else
		Test_Error "Fail to create $TARGET_TEST_DIR on target"
		return 1
	fi

	return 1
}

# function to record test result in $TEST_RESULT/testresult.log
Test_Print_Result()
{
	local PASS=0
	local FAIL=0
	local NORESULT=0
	if [ $2 -eq 0 ]; then
		PASS=1
	elif [ $2 -eq 1 ]; then
		FAIL=1
	else
		NORESULT=1
	fi

	# Format the output of the test result
	echo -e "$1 $PASS $FAIL $NORESULT" | awk '{printf("\t"); for(i=1;i<=NF;i++) printf("%-15s",$i); printf("\n");}' >> $TEST_RESULT/testresult.log
}

# Test_Kill_Qemu to kill child pid with parent pid given
# $1 is qemu process id, which needs to be killed
Test_Kill_Qemu()
{
	local ret=0
	local ppid=0
	local i=0
	declare local pid

	# Check if $1 pid exists and is a qemu process
	ps -fp $PID | grep -iq "qemu"

	# Find all children pid of the pid $1
	if [ $? -eq 0 ]; then

		# Check if there is any child pid of the pid $PID
		ppid=$PID
		ps -f --ppid $ppid
		ret=$?

		while [ $ret -eq 0 ]
		do
			# If yes, get the child pid and check if the child pid has other child pid
			# Continue the while loop until there is no child pid found
			pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
			ppid=${pid[$i]}
			i=$((i+1))
			ps -f --ppid $ppid
			ret=$?
		done

		# Kill these children pids from the last one
		while [ $i -ne 0 ]
		do
			i=$((i-1))
			kill ${pid[$i]}
			sleep 2
		done

		# Kill the parent id
		kill $PID
	fi

	return
}

# function to check if there is any qemu process
Test_Check_Qemu_UP()
{
	local count=`ps -ef | grep -c qemu`
	if [ ${count} -lt 2 ]; then
		Test_Info "There is no Qemu process"
		return 1
	else
		Test_Info "There is at least Qemu process running"
		return 0
	fi
}

# function to check if network is up
Test_Check_IP_UP()
{
	ping -c1 $1
	if [ $? -ne 0 ]; then
		Test_Info "IP $1 is not up"
		return 1
	else
		Test_Info "IP $1 is up"
		return 0
	fi
}

# function to find kernel/rootfs image
Test_Find_Image()
{
	where=""
	kernel=""
	arch=""
	target=""
	extension=""
	rootfs=""

	while getopts "l:k:a:t:" Option
	do
		case $Option in
			l) where="$OPTARG"
			   ;;
			k) kernel="$OPTARG"
			   extension="bin"
			   ;;
			a) arch="$OPTARG"
			   ;;
			t) target="$OPTARG"
			   extension="ext3"
			   ;;
			*) echo "invalid option: -$Option" && return 1
			   ;;
		 esac
	done

	if [ ! -z $kernel ]; then
		if [ -L ${where}/${kernel}-${arch}.${extension} ]; then
			echo ${where}/${kernel}-${arch}.${extension}
			return 0
		else
			for i in `dir ${where}`
			do
				echo $i | grep -q "${kernel}.*${arch}.*\.${extension}"
				if [ $? -eq 0 ]; then
					echo ${where}/${i}
					return 0
				fi
			done
			return 1
		fi
	fi

	if [ ! -z $target ]; then
		if [ -L ${where}/${target}-${arch}.${extension} ]; then
			rootfs=`readlink -f ${where}/${target}-${arch}.${extension}`
			echo ${rootfs}
			return 0
		else
			for i in `dir ${where}`
			do
				echo $i | grep -q "${target}-${arch}.*\.${extension}"
				if [ $? -eq 0 ]; then
					echo ${where}/${i}
					return 0
				fi
			done
			return 1
		fi
	fi
	return 1
}

# function to parse IP address of target
# $1 is the pid of qemu startup process
Test_Fetch_Target_IP()
{
	local opid=$1
	local ppid=0
	local ip_addr=0
	local i=0
	declare local pid

	# Check if $1 pid exists and contains ipaddr of target
	ps -fp $opid | grep -oq "192\.168\.7\.[0-9]*::"

	# Find all children pid of the pid $1
	# and check if they contain ipaddr of target
	if [ $? -ne 0 ]; then
		# Check if there is any child pid of the pid $1
		ppid=$opid
		ps -f --ppid $ppid > /dev/zero
		ret=$?

		while [ $ret -eq 0 ]
		do
			# If yes, get the child pid and check if the child pid has other child pid
			# Continue the while loop until there is no child pid found
			pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
			ppid=${pid[$i]}
			i=$((i+1))
			ps -f --ppid $ppid > /dev/zero
			ret=$?
		done

		# Check these children pids, if they have ipaddr included in command line
		while [ $i -ne 0 ]
		do
			i=$((i-1))
			ps -fp ${pid[$i]} | grep -oq "192\.168\.7\.[0-9]*::"
			if [ $? -eq 0 ]; then
				ip_addr=`ps -fp ${pid[$i]} | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
			fi
			sleep 1
		done
	else
		ip_addr=`ps -fp $opid | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
	fi

	echo $ip_addr

	return
}

# function to check if qemu and its network
Test_Create_Qemu()
{
	local timeout=$1
	local ret=1
	local up_time=0

	which poky-qemu
	if [ $? -eq 0 ]; then
		RUNQEMU=`which poky-qemu`
	else
		Test_Error "Can not find poky-qemu in \$PATH, return fail"
		exit 1
	fi
	
	if [ "$QEMUARCH" = "qemux86" -o "$QEMUARCH" = "qemux86-64" ]; then
		KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k bzImage -a ${QEMUARCH})
	elif [ "$QEMUARCH" = "qemuarm" -o "$QEMUARCH" = "spitz" -o "$QEMUARCH" = "borzoi" -o "$QEMUARCH" = "akita" -o "$QEMUARCH" = "nokia800" -o "$QEMUARCH" = "qemuppc" ]; then
		KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k zImage -a ${QEMUARCH})
	elif [ "$QEMUARCH" = "qemumips" ]; then
		KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k vmlinux -a ${QEMUARCH})
	fi

	# If there is no kernel image found, return failed directly
	if [ $? -eq 1 ]; then
		Test_Info "No kernel image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
		return $ret
	fi
	
	ROOTFS_IMAGE=$(Test_Find_Image -l ${DEPLOY_DIR}/images -t ${QEMUTARGET} -a ${QEMUARCH})

	# If there is no rootfs image found, return failed directly
	if [ $? -eq 1 ]; then
		Test_Info "No ${QEMUTARGET} rootfs image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
		return $ret
	fi

	TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3"
	
	CP=`which cp`
	if [ -e "$TEST_ROOTFS_IMAGE" ]; then
		rm -rf $TEST_ROOTFS_IMAGE
	fi
	$CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE

	if [ $? -ne 0 ]; then
		Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail"
		return $ret
	fi

	export MACHINE=$QEMUARCH

	# Create Qemu in localhost VNC Port 1
    	xterm -display ${DISPLAY} -e "${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" &

	# Get the pid of the xterm processor, which will be used in Test_Kill_Qemu
	PID=$!

	sleep 5
	
	while [ ${up_time} -lt ${timeout} ]
	do
		Test_Check_Qemu_UP
		if [ $? -ne 0 ]; then
			Test_Info "Wait for qemu up..."
			up_time=`expr $up_time + 5`
			sleep 5
		else
			Test_Info "Begin to check if qemu network is up"
			break
		fi
	done

	# Parse IP address of target from the qemu command line
	if [ ${up_time} -lt ${timeout} ]; then
		sleep 5
		TARGET_IPADDR=`Test_Fetch_Target_IP $PID`
		# If IP address is 0, means there is no qemu process found
		if [ ${TARGET_IPADDR} -eq 0 ]; then
			Test_Info "There is no qemu process or qemu ip address found, return failed"
			return $ret
		fi
	fi

	while [ ${up_time} -lt ${timeout} ]
	do
		Test_Check_IP_UP ${TARGET_IPADDR}
		if [ $? -eq 0 ]; then
			Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK"
			ret=0
			break
		else
			Test_Info "Wait for Qemu Network up"
			up_time=`expr $up_time + 5`
			sleep 5
		fi
	done

	if [ $ret -eq 0 ]; then
		Test_Info "Qemu and its network is up"
		return $ret
	else
		Test_Info "Qemu or its network is not up in ${timeout}"
		return $ret
	fi
}