Index: m3-sys/cm3/src/Builder.m3 =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cm3/src/Builder.m3,v retrieving revision 1.34 diff -u -r1.34 Builder.m3 --- m3-sys/cm3/src/Builder.m3 9 May 2010 10:08:11 -0000 1.34 +++ m3-sys/cm3/src/Builder.m3 20 May 2010 14:58:00 -0000 @@ -246,6 +246,8 @@ BEGIN DumpUnits (units); ETimer.ResetAll (); + + <* ASSERT Text.Equal(main, nm.base) *> SetupNamingConventionsInternal (s, mach); s.result_name := main; @@ -548,7 +550,7 @@ (* and write them *) Msg.Commands ("exhale ", s.info_name); wr := Utils.OpenWriter (s.info_name, fatal := TRUE); - MxOut.WriteUnits (units, wr); + MxOut.WriteUnits (s.result_name, units, wr); Utils.CloseWriter (wr, s.info_name); ETimer.Pop (); Index: m3-sys/cminstall/src/config-no-install/Darwin.common =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cminstall/src/config-no-install/Darwin.common,v retrieving revision 1.38 diff -u -r1.38 Darwin.common --- m3-sys/cminstall/src/config-no-install/Darwin.common 13 May 2010 09:35:30 -0000 1.38 +++ m3-sys/cminstall/src/config-no-install/Darwin.common 20 May 2010 14:58:00 -0000 @@ -142,6 +142,7 @@ if not equal (ret_code, 0) return ret_code end if shared + options += finish_exports_file(lib) % build the shared library ret_code = try_exec ( "@" & SYSTEM_CC, "-dynamiclib", @@ -168,7 +169,8 @@ "-dead_strip", % "-dead_strip_dylibs", % requires 10.5 objects, - imported_libs + imported_libs, + options, ) if not equal (ret_code, 0) delete_file (lib_a) @@ -246,6 +248,16 @@ %------------------------------------------------------------------- +proc dump_c_symbols(object) is + % HOST vs. TARGET confusion! + % We need to implement reading the files in Modula-3. + % And do a better job at symbol selection. + %exec("@nm -jgs __TEXT __text " & object & " > " & object & ".exp") + %exec("@nm -jgs __TEXT __literal4 " & object & " >> " & object & ".exp") +end + +%------------------------------------------------------------------- + include ("Unix.common") %------------------------------------------------------------------- Index: m3-sys/cminstall/src/config-no-install/Linux.common =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cminstall/src/config-no-install/Linux.common,v retrieving revision 1.11 diff -u -r1.11 Linux.common --- m3-sys/cminstall/src/config-no-install/Linux.common 17 Feb 2010 05:03:54 -0000 1.11 +++ m3-sys/cminstall/src/config-no-install/Linux.common 20 May 2010 14:58:00 -0000 @@ -32,5 +32,12 @@ "X11" : [ "-L/usr/X11R6/lib", "-lXaw", "-lXmu", "-lXext", "-lXt", "-lSM", "-lICE", "-lX11" ] } +proc dump_c_symbols(object) is + % HOST vs. TARGET confusion! + % We need to implement reading the files in Modula-3. + % And do a better job at symbol selection. + %exec("@nm --defined-only --extern-only " & object & " | grep -v ^_ | cut -f3 -d ' ' > " & object & ".exp") +end + include("Unix.common") include("gnuld.common") Index: m3-sys/cminstall/src/config-no-install/Solaris.common =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cminstall/src/config-no-install/Solaris.common,v retrieving revision 1.42 diff -u -r1.42 Solaris.common --- m3-sys/cminstall/src/config-no-install/Solaris.common 13 May 2010 09:35:30 -0000 1.42 +++ m3-sys/cminstall/src/config-no-install/Solaris.common 20 May 2010 14:58:00 -0000 @@ -131,17 +131,26 @@ return ret_code end - local shared_option = "" - if shared and equal(C_COMPILER, "GNU") - shared_option = "-shared" - end - if shared + + if equal(C_COMPILER, "GNU") + options += ["-shared"] + end + + if FileExists(lib & ".exports.sun") + if equal(C_COMPILER, "SUN") + options += ["-M", lib & ".exports.sun"] + end + if equal(C_COMPILER, "GNU") + options += ["-Wl,-M," & lib & ".exports.sun"] + end + end + % then, build the shared library configure_linker() ret_code = try_exec ("@" & SYSTEM_LD, shared_option, "-G", "-o", lib_sox, "-h", lib_sox, objects, - imported_libs) + imported_libs, options) if not equal (ret_code, 0) return ret_code end @@ -173,6 +182,13 @@ % don't build up large RPATH M3_SHARED_LIB_ARG = "" +proc dump_c_symbols(object) is + % HOST vs. TARGET confusion! + % We need to implement reading the files in Modula-3. + % And do a better job at symbol selection. + %exec("@/usr/ccs/bin/nm -pgh " & object & " | grep -v " U " | cut -f3 -d ' ' > " & object & ".exp") +end + include ("Unix.common") M3_MAIN_IN_C = TRUE Index: m3-sys/cminstall/src/config-no-install/Unix.common =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cminstall/src/config-no-install/Unix.common,v retrieving revision 1.60 diff -u -r1.60 Unix.common --- m3-sys/cminstall/src/config-no-install/Unix.common 12 May 2010 12:30:38 -0000 1.60 +++ m3-sys/cminstall/src/config-no-install/Unix.common 20 May 2010 14:58:00 -0000 @@ -64,7 +64,7 @@ end if not defined("m3back_pic") - m3back_pic = "-fPIC" + m3back_pic = "-fpic" end % -funwind-tables in anticipation of using libunwind @@ -83,6 +83,7 @@ proc m3_backend(source, object, optimize, debug) is local args = [ "-quiet", "-fno-reorder-blocks", + %"-fvisibility=hidden", m3back_unwind_table, m3back_pic, m3back_m32, @@ -108,6 +109,11 @@ if not defined ("compile_c") +if not defined("dump_c_symbols") + proc dump_c_symbols(object) is + end +end + proc compile_c(source, object, options, optimize, debug) is % hack @@ -120,8 +126,12 @@ local args = options if M3_PROFILING args += "-pg" end - return try_exec ("@" & SYSTEM_CC, args, "-c", source) + local a = try_exec ("@" & SYSTEM_CC, args, "-c", source, "-o", object) + if equal(a, 0) + dump_c_symbols(object) end + return a + end end @@ -223,15 +233,17 @@ end if shared + options += finish_exports_file(lib) - local soname_opt = "-Wl," & soname_flag & "," & lib_sox + if defined("GnuLinker") + options += ["-Bsymbolic"] + end + local soname_opt = "-Wl," & soname_flag & "," & lib_sox if IsInterix() - % move libfoo.a to libfoo.a.sa; sa for standalone (or static) % libfoo.a is the import library for libfoo.so % libfoo.a.sa is a static library if the dependency is being avoided - MoveFile(lib_a, lib0_file) soname_opt = "" expfile = "lib" & lib & ".exp" % libfoo.exp @@ -247,9 +259,9 @@ end configure_linker() if IsInterix() - ret_code = try_exec( "@" & SYSTEM_LD, pg, "-shared", soname_opt, "-o", lib_sox, "--whole-archive", lib0_file, "--no-whole-archive", imported_libs, expfile) + ret_code = try_exec( "@" & SYSTEM_LD, pg, options, "-shared", soname_opt, "-o", lib_sox, "--whole-archive", lib0_file, "--no-whole-archive", imported_libs, expfile) else - ret_code = try_exec( "@" & SYSTEM_LD, pg, "-shared", soname_opt, "-o", lib_sox, objects, imported_libs) + ret_code = try_exec( "@" & SYSTEM_LD, pg, options, "-shared", soname_opt, "-o", lib_sox, objects, imported_libs) end if not equal(ret_code, 0) return ret_code @@ -344,3 +356,62 @@ M3_SHARED_LIB_ARG = "-Wl,-R" end % --- pass "-R" flags to the linker too. + +proc finish_exports_file(lib) is + + return [ ] + + local exp = lib & ".exports" + local sun = exp & ".sun" % and GNU + local allc = exp & ".allc" + local mac = exp & ".mac" + DeleteFiles([sun, mac, allc]) + + if not (FileExists(exp) and defined("fs_contents")) + return [ ] + end + + % combine all the C symbols into one file + + local a = try_exec("@cat *.exp > " & allc & " 2>/dev/null") + + % prepend underscore to Modula-3 symbols for Mac, and combine with C symbols + + fs_cp(allc, mac) + >> mac in + foreach a in split(fs_contents(exp), "\n") + write("_") % only for certain architectures? + write(a) + write("\n") + end + end + + % produce the Sun/GNU file + + > sun in + write("{\nglobal:\n") + foreach a in [split(fs_contents(allc), "\n"), split(fs_contents(exp), "\n")] + write(a) + write(";\n") + end + write("local:*;\n};\n") + end + + % return the compiler/linker switches to use the file + + if defined("GnuLinker") + return ["-Wl,--version-script=" & sun] + end + if equal(TARGET_OS, "SOLARIS") + if equal(C_COMPILER, "SUN") + return ["-M", sun] + end + if equal(C_COMPILER, "GNU") + return ["-Wl,-M," & sun] + end + end + if equal(TARGET_OS, "DARWIN") + return ["-exported_symbols_list", mac] + end + return [ ] +end Index: m3-sys/cminstall/src/config-no-install/gnuld.common =================================================================== RCS file: /usr/cvs/cm3/m3-sys/cminstall/src/config-no-install/gnuld.common,v retrieving revision 1.1 diff -u -r1.1 gnuld.common --- m3-sys/cminstall/src/config-no-install/gnuld.common 12 May 2009 08:54:15 -0000 1.1 +++ m3-sys/cminstall/src/config-no-install/gnuld.common 20 May 2010 14:58:00 -0000 @@ -12,3 +12,5 @@ else M3_SHARED_LIB_ARG = "-Wl,-rpath," end + +GnuLinker = TRUE Index: m3-sys/m3linker/src/MxOut.i3 =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3linker/src/MxOut.i3,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 MxOut.i3 --- m3-sys/m3linker/src/MxOut.i3 14 Jan 2001 13:40:37 -0000 1.1.1.1 +++ m3-sys/m3linker/src/MxOut.i3 20 May 2010 14:58:22 -0000 @@ -11,7 +11,7 @@ (*------------------------------------------------------------------------*) -PROCEDURE WriteUnits (units: Mx.UnitList; output: Wr.T); +PROCEDURE WriteUnits (name: TEXT; units: Mx.UnitList; output: Wr.T); (* write the linker info for the 'units' on 'output'. This is the inverse of 'MxIn.ReadUnits' *) Index: m3-sys/m3linker/src/MxOut.m3 =================================================================== RCS file: /usr/cvs/cm3/m3-sys/m3linker/src/MxOut.m3,v retrieving revision 1.2 diff -u -r1.2 MxOut.m3 --- m3-sys/m3linker/src/MxOut.m3 12 Mar 2010 11:16:43 -0000 1.2 +++ m3-sys/m3linker/src/MxOut.m3 20 May 2010 14:58:22 -0000 @@ -11,7 +11,8 @@ IMPORT Wr, IntIntTbl; IMPORT M3Buf, M3ID; -IMPORT Mx, MxVS, MxIO; +IMPORT Mx, MxVS, MxIO, Text, FileWr; +<*FATAL ANY*> TYPE State = RECORD @@ -21,13 +22,76 @@ next_name : INTEGER := 0; vsMap : IntIntTbl.T := NIL; next_vs : INTEGER := 0; + exports : Wr.T := NIL; END; -PROCEDURE WriteUnits (units: Mx.UnitList; output: Wr.T) = +PROCEDURE OpenExports(VAR s: State; name: TEXT) = +(* Write out export lists to be later transformed for each linker. *) + BEGIN + s.exports := FileWr.Open (name & ".exports"); + END OpenExports; + +PROCEDURE CloseExports(VAR s: State) = + BEGIN + Wr.Close(s.exports); + END CloseExports; + +PROCEDURE AddExportText(VAR s: State; a: TEXT) = + BEGIN + Wr.PutText(s.exports, a); + END AddExportText; + +PROCEDURE StartExport(<*UNUSED*>VAR s: State) = + BEGIN + END StartExport; + +PROCEDURE EndExport(VAR s: State) = + BEGIN + Wr.PutText(s.exports, "\n"); + END EndExport; + +PROCEDURE WriteExports(VAR s: State; u: Mx.Unit) = + VAR info: MxVS.Info; + syms: Mx.InfoList; + name: M3ID.T := u.name; + interface: BOOLEAN := u.interface; + BEGIN + IF NOT Text.Equal(M3ID.ToText(name), "M3_BUILTIN") THEN + StartExport(s); + AddExportText(s, M3ID.ToText(name)); + AddExportText(s, ARRAY BOOLEAN OF TEXT {"_M3", "_I3"}[interface]); + EndExport(s); + (*StartExport(s); + AddExportText(s, ARRAY BOOLEAN OF TEXT {"MM_", "MI_"}[interface]); + AddExportText(s, M3ID.ToText(name)); + EndExport(s);*) + END; + + IF u.interface THEN + (*syms := u.externals; ? *) + RETURN; + ELSE + syms := u.import_def_syms; + END; + + FOR i := syms.start TO syms.start + syms.cnt - 1 DO + MxVS.Get (u.info[i], info); + (* We also need to exclude hidden interfaces. *) + StartExport(s); + AddExportText(s, M3ID.ToText(info.source)); + AddExportText(s, "__"); + AddExportText(s, M3ID.ToText(info.symbol)); + EndExport(s); + END; +END WriteExports; + +PROCEDURE WriteUnits (name: TEXT; units: Mx.UnitList; output: Wr.T) = VAR s: State; BEGIN IF (units = NIL) THEN RETURN END; IF (output = NIL) THEN RETURN END; + + OpenExports(s, name); s.wr := output; s.buf := M3Buf.New (); @@ -41,11 +105,14 @@ MxIO.PutTxt (s.buf, Mx.LinkerMagic, Wr.EOL); WHILE (units # NIL) DO WriteUnit (s, units.unit); + WriteExports(s, units.unit); units := units.next; END; M3Buf.Flush (s.buf, s.wr); + CloseExports(s); + (* give the collector a chance. *) s.wr := NIL; s.buf := NIL;