From owner-freebsd-ports Thu May 30 14:10:10 1996 Return-Path: owner-ports Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA25570 for ports-outgoing; Thu, 30 May 1996 14:10:10 -0700 (PDT) Received: from platinum.com (gateway.platinum.com [206.214.170.2]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id OAA25553 for ; Thu, 30 May 1996 14:10:07 -0700 (PDT) Received: from mailhub.platinum.com ([172.17.26.25]) by gateway.platinum.com with ESMTP id <18549-3>; Thu, 30 May 1996 16:09:51 -0500 Received: from bigbert.vt.platinum.com by mailhub.platinum.com (8.7.4/) id QAA11237; Thu, 30 May 1996 16:09:14 -0500 (CDT) Received: from doh.vt.platinum.com by bigbert.vt.platinum.com (8.7.3/NX3.0S) id QAA10692; Thu, 30 May 1996 16:12:00 -0500 (CDT) From: "Brent J. Nordquist" Received: by doh.vt.platinum.com (8.6.12) id QAA26785; Thu, 30 May 1996 16:07:02 -0500 Message-Id: <199605302107.QAA26785@doh.vt.platinum.com> Subject: Re: Object files/formats To: jkh@time.cdrom.com (Jordan K. Hubbard) Date: Thu, 30 May 1996 16:07:01 -0500 Cc: freebsd-ports@freebsd.org In-Reply-To: <14584.831814161@time.cdrom.com> from "Jordan K. Hubbard" at May 11, 96 06:29:21 am Reply-to: nordquist@platinum.com (Brent J. Nordquist) X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-ports@freebsd.org X-Loop: FreeBSD.org Precedence: bulk [Jordan: I know you're pretty busy today! I'm not sure if you're the right person to deliver this to; if it's someone else, I'd appreciate it if you would pass this on. The patch enclosed is to fix the magic problem for objects and executables. Comments?] THE TASK There are at least two problems with file's identification of FreeBSD objects and executables. The first one was reported in freebsd-ports: Chuck Robey said: | I am working on trying to get tcl to load an object file, and I just | noticed that the file command is returning: | | tclIO.o: NetBSD/i386 position independent object file not stripped "Jordan K. Hubbard" replied: | They all say that. File's magic information has misidentified our | object files for as long as I can remember now - I noted this quite | a few months back myself, but so far nobody has done the hacking on | /etc/magic necessary to fix it. :) The second one is that some object files report "PDP-11 executable". I wanted to fix the portions of the magic file relevant to FreeBSD so objects and executables would be correctly identified. CONTEXT I have a 2.1-stable sup'ed on May 5. The freebsd magic subfile I started with is version 1.1.6.2. (NOTE that according to the check-in comments, the -current version is different, because of the core file format.) WHAT I DID (1) I tried to carefully follow the structure of the a.out format, as laid out in . In particular, the freebsd magic subfile now uses the proper masks to get the magic, middle, and flag components. (2) It seems that the 134 value for the middle component (platform) is used for all the BSD/i386 platforms, including at least FreeBSD and NetBSD. As a result, the freebsd magic subfile now prints "BSD/i386", not "FreeBSD/i386", because it looks to me like you can't tell. (If someone who knows more about this knows how to tell them apart, by all means let's put in some more sub-rules.) (3) Some of the object files produced by the compiler have the right magic number, but oddly enough, in big-endian order. The netbsd magic subfile is smart enough to handle this, by repeating all the sections, changing lelong to belong, etc.. That's why some of our object files were being labeled as "NetBSD/i386 object file", the original issue that got me interested in this. I adopted this technique in the freebsd file. (4) I removed the lines commented with: # This covers object files, and is better than "PDP-11 executable" because they were never triggered, and were thus superfluous. (This was because the whole long was being checked, rather than just the magic part: the low 16 bits.) This is why our object files with the 0407 magic were still being labeled as "PDP-11 executable". TESTING I rebuilt the full magic file and tested it on all the object files (.o, .so, and .po) under /usr/obj, plus all the files in /usr/bin and /usr/lib. I assembled representative sample files, and compared file's output to that of the hexdump command. It looks to me like file is now producing the correct output. OBSERVATIONS (1) The old freebsd magic subfile used the entry point (long #6 at offset 20) to decide object file (less than 4k) vs. executable (4k and greater). I don't understand enough about the a.out format to know if this is rock-solid, or just a best-guess. I incorporated that logic into the new change. (2) The -current subfile is apparently different because of the core file format. The equivalent change will have to be made to the -current version. (3) At some point, someone should probably coordinate with the keepers of the magic subfiles (as documented in the README) to incorporate these changes. They will have to deal with the fact that the freebsd, netbsd, and linux magic subfiles all seem to lay claim to the same object format. My feeling is that common BSD/i386 formats that you can't tell apart should be merged together into one file, and be reported generically as "BSD/i386". CONTEXT DIFF FROM OLD SUBFILE (81 lines) begin 644 freebsd.diff M*BHJ(&9R965B2`S,"`Q,#HU-3HU,B`Q.3DV"BHJ*BHJ*BHJ*BHJ M*BHJ*@HJ*BH@,2PQ."`J*BHJ"B$@(R!T:&4@9F]L;&]W:6YG(&%R92!F;W(@ M,S@V0E-$+T9R965"4T0*("`*(2`P"6QE;&]N9PD)"3`T,3`)"7!U71E"0D))C!X.#`*(2`^/C(P"6QE M;&]N9PD)"3PT,#DV"0ES:&%R960@;&EB0HA(#X^,C`);&5L;VYG"0D) M/30P.38)"61Y;F%M:6-A;&QY(&QI;FME9"!E>&5C=71A8FQE"B$@/CXR,`EL M96QO;F<)"0D^-#`Y-@D)9'EN86UI8V%L;'D@;&EN:V5D(&5X96-U=&%B;&4* M(2`^,PEB>71E"0D)7C!X.#`)"65X96-U=&%B;&4*("`^,38);&5L;VYG"0D) M/C`)"6YO="!S=')I<'!E9`H@(`HA(",@5&AI&5C=71A8FQE(@HA M(#`);&5L;VYG"0D),#`P,#`P-#`W"6EM<'5R92!F;W)M870*("`^,38);&5L M;VYG"0D)/C`)"6YO="!S=')I<'!E9`H@(`H@(",@6%A8(&=R;W-S(&AA8VL@ M=&\@:61E;G1I9GD@8V]R92!F:6QE71E M)C!X0S`)"3!X,#`)"6]B:F5C=`HA(#XR,`EL96QO;F<)"0D^-#`Y-0HA(#X^ M,PEB>71E)C!X.#`)"3!X.#`)"61Y;F%M:6-A;&QY(&QI;FME9"!E>&5C=71A M8FQE"B$@/CXS"6)Y=&4F,'@X,`D),'@P,`D)97AE8W5T86)L90H@(#XQ-@EL M96QO;F<)"0D^,`D);F]T('-T71E)C!X0S`)"28P>#@P"0ES:&%R960@;&EB0HA M(#X^,PEB>71E)C!X0S`)"3!X-#`)"5!)0R!O8FIE8W0*(2`^/C,)8GET928P M>$,P"0DP>#`P"0EO8FIE8W0*(2`^,C`);&5L;VYG"0D)/C0P.34*(2`^/C,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