view lwlink/lwlink.c @ 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 c6a38fd8bd33
children
line wrap: on
line source

/*
lwlink.c
Copyright © 2009 William Astle

This file is part of LWLINK.

LWLINK 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/>.



*/

#define __lwlink_c_seen__

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <lw_alloc.h>
#include <lw_string.h>

#include "lwlink.h"

int debug_level = 0;
int outformat = OUTPUT_DECB;
char *outfile = NULL;
char *scriptfile = NULL;
int symerr = 0;
char *map_file = NULL;

fileinfo_t **inputfiles = NULL;
int ninputfiles = 0;

int nlibdirs = 0;
char **libdirs = NULL;

int nscriptls = 0;
char **scriptls = NULL;

char *sysroot = "/";

char *entrysym = NULL;

void add_input_file(char *fn)
{
	inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1));
	inputfiles[ninputfiles] = lw_alloc(sizeof(fileinfo_t));
	memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t));
	inputfiles[ninputfiles] -> forced = 1;
	inputfiles[ninputfiles++] -> filename = lw_strdup(fn);
}

void add_input_library(char *libname)
{
	inputfiles = lw_realloc(inputfiles, sizeof(fileinfo_t *) * (ninputfiles + 1));
	inputfiles[ninputfiles] = lw_alloc(sizeof(fileinfo_t));
	memset(inputfiles[ninputfiles], 0, sizeof(fileinfo_t));
	inputfiles[ninputfiles] -> islib = 1;
	inputfiles[ninputfiles] -> forced = 0;
	inputfiles[ninputfiles++] -> filename = lw_strdup(libname);	
}

void add_library_search(char *libdir)
{
	libdirs = lw_realloc(libdirs, sizeof(char*) * (nlibdirs + 1));
	libdirs[nlibdirs] = lw_strdup(libdir);
	nlibdirs++;
}

void add_section_base(char *sectspec)
{
	char *base;
	int baseaddr;
	char *t;
	int l;
	
	base = strchr(sectspec, '=');
	if (!base)
	{
		l = strlen(sectspec);
		baseaddr = 0;
	}
	else
	{
		baseaddr = strtol(base + 1, NULL, 16);
		l = base - sectspec;
		*base = '\0';
	}
	baseaddr = baseaddr & 0xffff;
	
	t = lw_alloc(l + 25);
	sprintf(t, "section %s load %04X", sectspec, baseaddr);
	if (base)
		*base = '=';
	
	scriptls = lw_realloc(scriptls, sizeof(char *) * (nscriptls + 1));
	scriptls[nscriptls++] = t;
}

char *sanitize_symbol(char *symbol)
{
	static char symbuf[2048];
	char *sym = symbol;
	char *tp = symbuf;
	
	for (; *sym; sym++)
	{
		int c1 = *sym;
		if (c1 == '\\')
		{
			*tp++ = '\\';
			*tp++ = '\\';
			continue;
		}
		if (c1 < 32 || c1 > 126)
		{
			int c;
			*tp++ = '\\';
			c = c1 >> 4;
			c += 48;
			if (c > 57)
				c += 7;
			*tp++ = c;
			c = c1 & 15;
			c += 48;
			if (c > 57)
				c += 7;
			*tp++ = c;
			continue;
		}
		*tp++ = c1;
	}
	*tp = 0;
	return symbuf;
}