view extra/ld @ 418:3832a68d83ef

Fix internal compiler error on "var2 = var1 + 1" patterns This appears to be the correct fix. It was provided by Tormod Volden (debian.tormod@gmail.com). The final commit is substantially different from Tormod's submission mostly due to housecleaning (removing the old patches and updating the README). Tormod's comments follow. The original addhi_mem_1 "insn" instruction pattern /matches/ two memory operands, just with the /constraint/ that these are the same location. A pattern match tells the compiler "you should be able to use this, but you might have to work on it to meet the constraints". For typical constraints on registers the compiler can add "reloads", moving stuff between registers or from memory, until the constraints are met and the instruction can be used. However, in this case, no amount of reloads can make two memory locations the same if they already weren't, so the compiler breaks down and cries "unable to generate reloads". It seems this issue only appears if optimization is enabled. The proof is in gcc's reload.c and is left as an exercise to the reader. Limiting the matching pattern to identical memory operands avoids these situations, while allowing the common "var++" cases. References: The pattern/constraints difference is explained in https://gcc.gnu.org/onlinedocs/gccint/Simple-Constraints.html#index-other-register-constraints-3335
author William Astle <lost@l-w.ca>
date Tue, 29 Mar 2016 21:21:49 -0600
parents 26d2791672b1
children a3711f5ac569
line wrap: on
line source

#!/bin/sh
#
#
# Copyright 2009 by William Astle <lost@l-w.ca>
#
#This file is part of LWTOOLS.
#
#LWTOOLS is free software: you can redistribute it and/or modify it under the
#terms of the GNU General Public License as published by the Free Software
#Foundation, either version 3 of the License, or (at your option) any later
#version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT
#ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
#more details.
#
#You should have received a copy of the GNU General Public License along with
#this program. If not, see <http://www.gnu.org/licenses/>.

# this was based somewhat on the "as" script from gcc6809

#echo "LWTOOLS-ld $0 $*"
path_to_lwlink=lwlink

# Set defaults.  Some are based on the target type, which is 
# determined by the name by which the program was invoked.
output_file=a.out
libpaths=
libs=
stdlibpaths="-L=/usr/local/lib -L=/usr/lib -L=/lib"
verbose=

if [ "$verbose" = 1 ]; then
	echo "$0 $@"
fi

case $0 in
	*m6809-coco-*)
		options="--format=decb"
#		options="-b .text=0x2000 -b .data=0x7000 -b .bss=0x7C00 -b .ctors=0x7F00 -b .dtors=0x7F80 -b vector=0x7FF0"
#		aslink_options="-nwxst"
#		exe_suffix=.bin
		;;
	*)
		options="--format=raw"
#		options="-b .text=0x8000 -b .data=0x1000 -b .bss=0x0100 -b .ctors=0xFD00 -b .dtors=0xFE00 -b vector=0xFFF0"
#		aslink_options="-nwxso"
#		exe_suffix=.s19
		;;
esac


while [ "$*" != "" ]; do
	arg=$1; shift
	case $arg in
		-d|-dc|-dp)
			# force allocation of space to common symbols
			# even if relocatable output file is specified
			# not supported by targets
			;;
		-X)
			# strip unneeded stuff
			# ignored - really just a no-op
			;;
		-gn)
			# Generate NoICE debug file
			# ignored because debugging not supported by targets
			;;
		-gs)
			# Generate SDCC debug file
			# ignored because debugging not supported by targets
			;;
		-o)
			output_file=$1; shift
			;;
		-L*)
			arg=${arg#-L}
			libpaths="$libpaths --library-path=$arg"
			;;
		-l*)
			arg=${arg#-l}
			libs="$libs --library=$arg"
			;;
		--section-start)
			section_value=$1; shift
			options="$options --section-base=$section_value"
			;;
		
		-Map=*)
			arg=${arg#-Map=}; shift
			options="$options --map=$arg"
			;;
			
		--script=*)
			options="$options $arg"
			;;
		-T)
			options="$options --script=$1"; shift
			;;
		-Tbss)
			options="$options --section-base=.bss=$1"; shift
			;;
		-Tdata)
			options="$options --section-base=.data=$1"; shift
			;;
		-Ttext|-Tcode)
			options="$options --section-base=.text=$1"; shift
			;;
		-v|--verbose)
			verbose=1
			;;
		*crt0.o)
			startup_files=$arg
			;;
		-g)
			# Ignored by GNU ld; we should do the same
			;;
		-h|--help)
			echo "ld (m6809)"
			exit 0
			;;
		--format-lwex)
			options="$options --format=lwex"
			;;
		
		--sysroot=*)
			options="$options $arg"
			;;
			
		-nostdlib)
			stdlibpaths=
			;;
		
		-e)
			options="$options --entry=$1"
			shift
			;;
			
		--entry)
			options="$options $arg"
			;;

		--relax)
			;;
		--start-group)
			;;
		--end-group)
			;;
		--gc-sections)
			;;
		-*)
			echo "ld (m6809): unknown option $arg"
			exit 1
			;;
		*)
			input_files="$input_files $arg"
			;;
	esac
done

options="$options -o $output_file"

if [ "$verbose" = "1" ]; then
	echo "$path_to_lwlink $options $input_files $startup_files $libpaths $stdlibpaths $libs"
fi

$path_to_lwlink $options $input_files $startup_files $libpaths $libs
rc=$?

if [ "$rc" != "0" ]; then
	rm -f $output_file
	exit $rc
fi