From owner-freebsd-arch@FreeBSD.ORG Sat Nov 28 18:49:42 2009 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F0281065672 for ; Sat, 28 Nov 2009 18:49:42 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id B7EAE8FC08 for ; Sat, 28 Nov 2009 18:49:41 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 39409730DA; Sat, 28 Nov 2009 19:57:45 +0100 (CET) Date: Sat, 28 Nov 2009 19:57:45 +0100 From: Luigi Rizzo To: arch@freebsd.org Message-ID: <20091128185745.GA7612@onelab2.iet.unipi.it> References: <20091122111732.GA45909@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline In-Reply-To: <20091122111732.GA45909@onelab2.iet.unipi.it> User-Agent: Mutt/1.4.2.3i X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: [[atch] Re: anyone interested in helping fixing the 'tcc' compiler ? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Nov 2009 18:49:42 -0000 --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline followup to myself due to scarce success... I have done some partial step in fixing the ELF produced by tcc to work with freebsd. A patch is attached which works for simple programs but not for more complex ones. I found the following problems: - tcc does not produce a PHDR program header, which caused the linker to fail. This should be fixed by this patch. - the relocation sections produced by tcc apparently include a mix of JMP and non JMP relocations in the same place. Our loader complains when it finds this mix. I have changed the section definitions but it seems to work only for simple things (Hello World -style). - the relocation info is not in the place rtld is looking for. What i found is that UNDEF symbols had the offset to be patched in the dynsym section, instead of the .got section where (apparently) our loader is looking for. The function patch_dynsym_undef() in the patch attached seems to handle this, but I am not sure how general is this. With this patch the simplest example programs (ex1, ex2, ex3, ex5) do work, but ex4 (which uses -lX11) fails to load ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/i386/reloc.c:292 (I hope i can track this later). cheers luigi On Sun, Nov 22, 2009 at 12:17:32PM +0100, Luigi Rizzo wrote: > Hi, > I have recently started playing with the Tiny C Compuler (lang/tcc) > which is amazingly useful for prototyping, but has problem generating > non-static binaries in FreeBSD -- basically it produces a bogus > elf file which our loader does not like. > Static binaries work fine, as well as 'tcc -run ' (compile > and run on the fly -- you should really try it if you haven't yet). > > There is an open PR on this > > http://www.freebsd.org/cgi/query-pr.cgi?pr=138481 > > and the problem is known upstream but no fix > > http://lists.gnu.org/archive/html/tinycc-devel/2005-07/msg00070.html > > However, from the description it does not seem a horribly > hard problem. Perhaps someone with a bit of knowledge on > how our ld-elf.so works should not have a hard time pinpointing > the problem so that other people can fix it ? > > Any takers ? > > cheers > luigi --Nq2Wo0NMKNjxTN9z--