From owner-freebsd-toolchain@FreeBSD.ORG Fri Nov 30 11:21:05 2012 Return-Path: Delivered-To: freebsd-toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 643F6FF8 for ; Fri, 30 Nov 2012 11:21:05 +0000 (UTC) (envelope-from pete.chou@gmail.com) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id C7A458FC12 for ; Fri, 30 Nov 2012 11:21:04 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id go10so461105lbb.13 for ; Fri, 30 Nov 2012 03:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=sUfzXb+j2eUrMC/OHlo4Je7dX/aDaoMiTHBDm/xPckY=; b=w4tX/FefIrQtSfw7zPzFtd5c7O/fQcvz75B/X8z/32tmQN9xP8mnivPukVNWjlDdum iJ8KVn3rwwGtXcgiR+MKR9YRdcjKZHwrqqS4rqYZN0iIEnbtNnGwM5RCmB5yh/Qyhutu DRSwMUhJ90OH+2aIKr8rCLxB6alHPCgT0EZE5KcWSfb1G7K2l0WXVKQNXcvtQEPe5cOK 6v6z8zXBGxn/UQUfEpN8FeaVRIsHL9yIabQ6+wXqv77l/oQ6eGbE/OW8sqvzhE0Ab8gM wmDus01mTrK9FKZ52oDjUh/u3R5S5iNop7sdz1RAUA08Bs5MQooSXhviM2R7b5KNaiT3 3AFw== Received: by 10.112.9.135 with SMTP id z7mr684744lba.66.1354274463119; Fri, 30 Nov 2012 03:21:03 -0800 (PST) MIME-Version: 1.0 Sender: pete.chou@gmail.com Received: by 10.114.69.131 with HTTP; Fri, 30 Nov 2012 03:20:32 -0800 (PST) In-Reply-To: References: From: pete Date: Fri, 30 Nov 2012 19:20:32 +0800 X-Google-Sender-Auth: SbdBGexFVtHTn4MuR9yt0erdlK4 Message-ID: Subject: Re: crunchide breaks object files when using mclinker to do base system linking To: Erik Cederstrand Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-toolchain@freebsd.org X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Nov 2012 11:21:05 -0000 I made a patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/174011 Not sure if it looks good to you since the changes are not small. With this patch, crunchide is able to handle object files generated by both gold and mclinker. And if using input from gnu ld, patched crunchide produces exactly the same output as before. However, now I check my patch on X86 FreeBSD only. Thanks, Pete On Tue, Nov 27, 2012 at 4:16 PM, Erik Cederstrand wrote: > Den 27/11/2012 kl. 09.00 skrev pete : > > > Hi, > > > > I meet a problem when using mclinker to do base system linking. And the > > problem is crunchide is gnu ld specific. it presumes the section layout > of > > a object file is like what gnu ld generates. > > > > To make it clear, gnu ld would generate the following layout. And > crunchide > > will update elf section header, symbol table, and then string table. (The > > string table is likely enlarged.) > > > > ld -dc -r -o cat.lo cat_stub.o > > /usr/obj/usr/src/rescue/rescue//usr/src/bin/cat/cat.o > > crunchide -k _crunched_cat_stub cat.lo > > > > ----gnu ld------------ > > + elf header + > > ---------------------- > > + + > > + + > > ---------------------- > > + elf section header + > > ---------------------- > > + symbol table + > > ---------------------- > > + string table + > > ---------------------- > > > > However, mclinker does not produce this layout, but put elf section > header > > in the end of file. And then crunchide will break the object file > generated > > by mclinker. (elf section header is overwritten by new strings) > > > > I know the layout generated by gold linker is also different to gnu ld. > On > > the other hand, we can find only ELF header is required to be fixed in > *"System > > V Application Binary Interface*". > > > > For mclinker, I think it's not difficult to add the change to be > compatible > > with gnu ld. But do you think if it will be better to modify crunchide > > utility to support more elf linkers? > > > Unless you have compelling technical reasons to keep your layout, I think > it's better for mclinker to be as compatible with GNU ld as possible, even > though your layout also adheres to the standards. If other tools in FreeBSD > or other platforms also make assumptions about the header layout, you'll > end up patching lots of tools instead of working on mclinker. > > With that in mind, I also think it's worthwhile to patch our crunchide to > be more permissive. If you have the resources, please send patches. > > Thanks, > Erik