[M3devel] PPC_DARWIN problems, at least config/5.2.6, maybe all moot
Tony Hosking
hosking at cs.purdue.edu
Wed Dec 26 05:17:56 CET 2007
On Dec 25, 2007, at 3:32 PM, Jay wrote:
> 1)
>
> The documentation says -fPIC is the default, so I removed it.
> But it matters. It doesn't matter for gcc building C.
> It matters for m3cg building Modula-3.
Please note that m3cg is based on the GNU release of gcc, *not* the
Darwin version. Thus, even though Darwin might have -fPIC as default
for Apple's gcc, GNU gcc might not.
> It is the difference between, pic:
>
> jbook:/dev2/j/m3 jay$ cat Hello.m3
> MODULE Hello EXPORTS Main;
>
> IMPORT IO;
> BEGIN
> IO.Put("Hello\n");
> END Hello.
>
> jbook:/dev2/j/m3 jay$ cat PPC_DARWIN/Hello.ms
> ...
> bl L_IO__Put$stub
> ...
> .data
> .picsymbol_stub
> L_IO__Put$stub:
> .indirect_symbol _IO__Put
> mflr r0
> bcl 20,31,L0$_IO__Put
> L0$_IO__Put:
> mflr r11
> addis r11,r11,ha16(L_IO__Put$lazy_ptr-L0$_IO__Put)
> mtlr r0
> lwz r12,lo16(L_IO__Put$lazy_ptr-L0$_IO__Put)(r11)
> mtctr r12
> addi r11,r11,lo16(L_IO__Put$lazy_ptr-L0$_IO__Put)
> bctr
> .data
> .lazy_symbol_pointer
> L_IO__Put$lazy_ptr:
> .indirect_symbol _IO__Put
> .long dyld_stub_binding_helper
>
> vs. non-pic just plain wow only one whole function to make a call :) :
>
> jbook:/dev2/j/m3 jay$ cat PPC_DARWIN/Hello.ms
> ...
> bl _IO__Put
>
> which nets you the likes of:
>
> jbook:/dev2/j/m3 jay$ cm3
> -> linking prog
> gcc -dynamic -o prog _m3main.o Hello.mo -L/cm3/pkg/libm3/
> PPC_DARWIN -lm3 -L/cm3/pkg/m3core/PPC_DARWIN -lm3core -L/cm3/bin/../
> lib -lm3gcdefs
> /usr/bin/ld: _m3main.o has external relocation entries in non-
> writable section (__TEXT,__text) for symbols:
> _RTProcess__Exit
> _RTLinker__AddUnit
> _RTLinker__InitRuntime
> collect2: ld returned 1 exit status
>
>
> (Windows also only uses one instruction, through a pointer, for
> dynamic calls, and the compiler often prefetches the pointer.
> The difference is, perhaps, that Windows aggregates all the
> pointers together, not sure about the other systems.. one instruction
> through a pointer is true for x86 and AM64, not so of the former
> MIPS, PowerPC, Alpha I believe or current IA64, those
> require fetching/restore the GOT/TOC (same thing? I should know the
> difference..)
>
> 2)
> Splitting -L and -l off for shared libs matters.
>
> ld /foo/bar.a means link to bar.a, which is a static lib, not even
> a stub lib or import lib like in Windows
>
> -L/foo -lbar probes for
> /foo/bar.dylib
> /foo/bar.a
>
> man ld:
> -lx This option is an abbreviation for the library
> name `libx.a',
> where x is a string. If -dynamic is specified the
> abbreviation
> for the library name is first search as
> `libx.dylib' and then
> `libx.a' is searched for. ld searches for
> libraries first in
> any directories specified with -L options, then in
> any directo-
> ries specified in the colon separated set of paths in
> the envi-
> ronment variable LD_LIBRARY_PATH, then the standard
> directories
> /lib, /usr/lib, and /usr/local/lib. A library is
> searched when
> its name is encountered, so the placement of the -l
> flag is sig-
> nificant. If string x is of the form x.o, then
> that file is
> searched for in the same places, but without
> prepending `lib' or
> appending `.a' or `.dylib' to the filename.
>
>
> 3)
> lastly, setting DYLD_LIBRARY_PATH=/cm3/lib
> lets the full paths from one machine not matter so much on another
> machine.
>
> I am going to try out:
>
> before:
> local lib_so = format ("lib%s.dylib", lib)
> local lib_soxx = format ("lib%s.%s.dylib", lib, version)
> local lib_pn = LIB_INSTALL & "/" & lib_soxx
>
> "-install_name", lib_pn,
>
> after:
>
> local lib_so = format ("lib%s.dylib", lib)
> local lib_soxx = format ("lib%s.%s.dylib", lib, version)
> local lib_pn = LIB_INSTALL & "/" & lib_soxx
>
> "-install_name", lib_soxx,
>
> see if a path is needed or can just use leaf names.
>
> - Jay
>
> From: jayk123 at hotmail.com
> To: m3devel at elegosoft.com
> Subject: PPC_DARWIN problems, at least config/5.2.6, maybe all moot
> Date: Tue, 25 Dec 2007 12:09:31 +0000
>
> PPC_DARWIN also has problems...at least in the config.
>
>
> If you take the 5.2.6 archive, install to /dev2/cm3, accept the
> defaults,
> claim all the missing unused libs are in /usr/lib (opengl,
> postgres, x11)
>
>
> you end up with:
>
>
> jbook:/dev2/j/m3 jay$ cat Hello.m3
>
>
> MODULE Hello EXPORTS Main;
> IMPORT IO;
> BEGIN
> IO.Put("Hello\n");
> END Hello.
>
>
> jbook:/dev2/j/m3 jay$ uname -a
> Darwin jbook 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10
> 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh
> powerpc
>
>
> jbook:/dev2/j/m3 jay$ cm3 -version
> Critical Mass Modula-3 version 5.2.6
> last updated: 2003-06-27
> configuration: /cm3/bin/cm3.cfg
>
>
> jbook:/dev2/j/m3 jay$ cm3
> new source -> compiling Hello.m3
> -> linking prog
>
>
> jbook:/dev2/j/m3 jay$ PPC_DARWIN/prog
> dyld: Library not loaded: /var/tmp/cm3/lib/libm3.5.2.dylib
> Referenced from: /dev2/j/m3/PPC_DARWIN/prog
> Reason: image not found
> Trace/BPT trap
>
>
> jbook:/dev2/j/m3 jay$ otool -L PPC_DARWIN/prog
> PPC_DARWIN/prog:
> /var/tmp/cm3/lib/libm3.5.2.dylib (compatibility version
> 5.0.0, current version 5.2.0)
> /Users/wagner/local/cm3/lib/libm3core.5.2.dylib
> (compatibility version 5.0.0, current version 5.2.0)
> /Users/wagner/local/cm3/lib/libm3gcdefs.5.2.dylib
> (compatibility version 5.0.0, current version 5.2.0)
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
> current version 88.1.10)
> /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
>
>
> jbook:/dev2/j/m3 jay$ ls -l PPC_DARWIN/prog
> -rwxr-xr-x 1 jay admin 20264 Dec 25 04:43 PPC_DARWIN/prog
>
>
> At the temporary cost of giving up dynamic linking, you can fix
> this by removing M3_SPLIT_LIBNAMES_IF_SHARED
> and/or M3_SPLIT_LIBNAMES from cm3.cfg, yielding:
>
>
> jbook:/dev2/j/m3 jay$ otool -L PPC_DARWIN/prog
> PPC_DARWIN/prog:
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
> current version 88.1.10)
>
>
> jbook:/dev2/j/m3 jay$ ls -l PPC_DARWIN/prog
> -rwxr-xr-x 1 jay admin 1388380 Dec 25 04:48 PPC_DARWIN/prog
>
>
> jbook:/dev2/j/m3 jay$ PPC_DARWIN/prog
> Hello
>
>
> I will fix the checked in config file...even though it varies a
> bunch from the 5.2.6 distributed
> config, it results in the same.
>
>
> And, um, does everyone understand what I did with Win32 and making
> cminstall obsolete?
> Ok to do the same on Mac OS X?
> You know, it's running things out of the path and/or finding them
> in their "very standard" locations.
> In fact, you can hard code full paths and be ok.
> That is, instead of asking the user where their compiler is,
> hardcoding any of cc, gcc, /usr/bin/cc, /usr/bin/gcc all work fine.
> Asking them where ar/ranlib are, similar, though the docs say that
> libtool replaced those, and ar/ranlib vs. libtool is one way
> in which the checked in config and the 5.2.6 distribution's config
> vary. I'll try for libtool.
>
>
> The only thing the user really needs to decide is where to install
> to, and
> the cfg file can discover their choice without any editing.
>
>
> INSTALL_ROOT = path() & "/.."
> BIN_INSTALL = path() % executables
>
>
> In terms of wanting to provide some configurable redirection, well,
> I think an advanced user can manage..
> An indirect SYSTEM_CC = "cc" can be left, I guess.
>
>
> You know, I dare say, that platforms have been reduced and
> converged enough such that..you can get rid of
> Quake and move it into cm3. Um.. do any of the Unix platforms
> support other than gcc? Other than GNU ld?
> Ok, Apple ld is not GNU ld. (Geez, it is just me or is Apple an
> incredible hodgepodge mess these days?
> I mean both in terms of their "system architecture" and their
> tools. The "system architecture" reveals bunches
> of similar redundant subsystems. Try reading through man ld, man
> ranlib, just try to understand which
> flag goes with which mode, which flags are for compatibility with
> which OS version, and which of the
> compatibility flags is either ignored or does something useful...
> and should I say -lGL or -framework OpenGL??)
>
>
> That I don't haven't adjusted to Modula-3 and don't mind/prefer
> writing Quake instead. :)
>
>
> Some bootstrap was provided. I should look at it, and its config.
> Otherwise..I'll look into what it takes to build it all and with
> dynamic linking.
> Perhaps the bootstrap is just fine. But the checked in config is not.
>
>
> - Jay
>
> Share life as it happens with the new Windows Live. Share now!
> Share life as it happens with the new Windows Live. Share now!
More information about the M3devel
mailing list