[pypy-commit] pypy kill-exported-symbols-list: whack whack wahck

arigo noreply at buildbot.pypy.org
Wed Oct 22 17:27:10 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: kill-exported-symbols-list
Changeset: r74090:b782b42ddc67
Date: 2014-10-22 17:26 +0200
http://bitbucket.org/pypy/pypy/changeset/b782b42ddc67/

Log:	whack whack wahck

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -199,6 +199,8 @@
             except (AttributeError, KeyError):
                 pass
         self.merge_eci(*all)
+        #
+        db.exported_symbols = set(self.eci.export_symbols)
 
     def get_gcpolicyclass(self):
         if self.gcpolicy is None:
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -829,9 +829,12 @@
 
     def forward_declaration(self):
         for funcgen in self.funcgens:
+            name = funcgen.name(self.name)
+            is_exported = name in self.db.exported_symbols
             yield '%s;' % (
                 forward_cdecl(self.implementationtypename,
-                    funcgen.name(self.name), self.db.standalone))
+                    name, self.db.standalone,
+                    is_exported=is_exported))
 
     def implementation(self):
         for funcgen in self.funcgens:
diff --git a/rpython/translator/c/src/entrypoint.h b/rpython/translator/c/src/entrypoint.h
--- a/rpython/translator/c/src/entrypoint.h
+++ b/rpython/translator/c/src/entrypoint.h
@@ -9,5 +9,5 @@
 #endif
 
 char *RPython_StartupCode(void);
-int PYPY_MAIN_FUNCTION(int argc, char *argv[]);
+RPY_EXPORTED int PYPY_MAIN_FUNCTION(int argc, char *argv[]);
 #endif  /* PYPY_STANDALONE */
diff --git a/rpython/translator/c/src/g_prerequisite.h b/rpython/translator/c/src/g_prerequisite.h
--- a/rpython/translator/c/src/g_prerequisite.h
+++ b/rpython/translator/c/src/g_prerequisite.h
@@ -25,4 +25,11 @@
 #endif
 
 
+#ifdef __GNUC__
+#  define RPY_EXPORTED __attribute__((visibility("default")))
+#else
+#  define RPY_EXPORTED __declspec(dllexport)
+#endif
+
+
 #include "src/threadlocal.h"
diff --git a/rpython/translator/c/support.py b/rpython/translator/c/support.py
--- a/rpython/translator/c/support.py
+++ b/rpython/translator/c/support.py
@@ -30,12 +30,16 @@
         __thread = "__thread "
     return __thread + ctype.replace('(@)', '@').replace('@', cname).strip()
 
-def forward_cdecl(ctype, cname, standalone, is_thread_local=False):
-    __thread = ""
+def forward_cdecl(ctype, cname, standalone, is_thread_local=False,
+                  is_exported=False):
+    prefix = ""
     if is_thread_local:
-        __thread = "__thread "
+        prefix = "__thread "
+    if is_exported:
+        assert not is_thread_local
+        prefix = "RPY_EXPORTED "
 
-    cdecl_str = __thread + cdecl(ctype, cname)
+    cdecl_str = prefix + cdecl(ctype, cname)
     if standalone:
         return 'extern ' + cdecl_str
     else:
diff --git a/rpython/translator/platform/__init__.py b/rpython/translator/platform/__init__.py
--- a/rpython/translator/platform/__init__.py
+++ b/rpython/translator/platform/__init__.py
@@ -153,18 +153,6 @@
             for line in stderr.splitlines():
                 log.WARNING(line)
 
-    def _make_response_file(self, prefix):
-        """Creates a temporary file with the specified prefix,
-        and returns its name"""
-        # Build unique filename
-        num = 0
-        while 1:
-            response_file = udir.join('%s%i' % (prefix, num))
-            num += 1
-            if not response_file.check():
-                break
-        return response_file
-
     def _make_o_file(self, cfile, ext):
         """Create an object file name under the udir for a .c file"""
         ofile = cfile.new(ext=ext)
@@ -192,7 +180,7 @@
         if standalone:
             extra = self.standalone_only
         else:
-            extra = self.shared_only
+            extra = self.get_shared_only_compile_flags()
         cflags = list(self.cflags) + list(extra)
         return (cflags + list(eci.compile_extra) + args)
 
@@ -210,16 +198,10 @@
         library_dirs = self._libdirs(library_dirs)
         libraries = self._libs(eci.libraries)
         link_files = self._linkfiles(eci.link_files)
-        export_flags = self._exportsymbols_link_flags(eci)
-        return (library_dirs + list(self.link_flags) + export_flags +
+        return (library_dirs + list(self.link_flags) +
                 link_files + list(eci.link_extra) + libraries +
                 list(self.extra_libs))
 
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if eci.export_symbols:
-            raise ValueError("This platform does not support export symbols")
-        return []
-
     def _finish_linking(self, ofiles, eci, outputfilename, standalone):
         if outputfilename is None:
             outputfilename = ofiles[0].purebasename
diff --git a/rpython/translator/platform/darwin.py b/rpython/translator/platform/darwin.py
--- a/rpython/translator/platform/darwin.py
+++ b/rpython/translator/platform/darwin.py
@@ -35,20 +35,6 @@
         include_dirs = self._includedirs(eci.include_dirs)
         return (args + frameworks + include_dirs)
 
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        response_file = self._make_response_file("dynamic-symbols-")
-        f = response_file.open("w")
-        for sym in eci.export_symbols:
-            f.write("_%s\n" % (sym,))
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        return ["-Wl,-exported_symbols_list,%s" % (response_file,)]
-
     def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
                      shared=False, headers_to_precompile=[],
                      no_precompile_cfiles = []):
diff --git a/rpython/translator/platform/posix.py b/rpython/translator/platform/posix.py
--- a/rpython/translator/platform/posix.py
+++ b/rpython/translator/platform/posix.py
@@ -42,29 +42,6 @@
     def _link_args_from_eci(self, eci, standalone):
         return Platform._link_args_from_eci(self, eci, standalone)
 
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        if sys.platform.startswith('freebsd'):
-            eci.export_symbols += ('__progname', 'environ')
-
-        response_file = self._make_response_file("dynamic-symbols-")
-        f = response_file.open("w")
-        f.write("{\n\tglobal:\n")
-        for sym in eci.export_symbols:
-            f.write("\t\t%s;\n" % (sym,))
-        f.write("\tlocal:\n\t\t*;\n};")
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        if (self.cc == 'mingw32' or (self.cc== 'gcc' and os.name=='nt')
-                or sys.platform == 'cygwin'):
-            return ["-Wl,--export-all-symbols,--version-script=%s" % \
-                    (response_file,)]
-        return ["-Wl,--export-dynamic,--version-script=%s" % (response_file,)]
-
     def _link(self, cc, ofiles, link_args, standalone, exe_name):
         args = [str(ofile) for ofile in ofiles] + link_args
         args += ['-o', str(exe_name)]
@@ -105,6 +82,9 @@
                 raise ValueError(msg)
         return result
 
+    def get_shared_only_compile_flags(self):
+        return tuple(self.shared_only) + ('-fvisibility=hidden',)
+
     def gen_makefile(self, cfiles, eci, exe_name=None, path=None,
                      shared=False, headers_to_precompile=[],
                      no_precompile_cfiles = []):
@@ -124,8 +104,6 @@
         if shared:
             linkflags = self._args_for_shared(linkflags)
 
-        linkflags += self._exportsymbols_link_flags(eci, relto=path)
-
         if shared:
             libname = exe_name.new(ext='').basename
             target_name = 'lib' + exe_name.new(ext=self.so_ext).basename
@@ -133,7 +111,7 @@
             target_name = exe_name.basename
 
         if shared:
-            cflags = self.cflags + self.shared_only
+            cflags = self.cflags + self.get_shared_only_compile_flags()
         else:
             cflags = self.cflags + self.standalone_only
 
diff --git a/rpython/translator/platform/windows.py b/rpython/translator/platform/windows.py
--- a/rpython/translator/platform/windows.py
+++ b/rpython/translator/platform/windows.py
@@ -186,20 +186,6 @@
         # Windows needs to resolve all symbols even for DLLs
         return super(MsvcPlatform, self)._link_args_from_eci(eci, standalone=True)
 
-    def _exportsymbols_link_flags(self, eci, relto=None):
-        if not eci.export_symbols:
-            return []
-
-        response_file = self._make_response_file("exported_symbols_")
-        f = response_file.open("w")
-        for sym in eci.export_symbols:
-            f.write("/EXPORT:%s\n" % (sym,))
-        f.close()
-
-        if relto:
-            response_file = relto.bestrelpath(response_file)
-        return ["@%s" % (response_file,)]
-
     def _compile_c_file(self, cc, cfile, compile_args):
         oname = self._make_o_file(cfile, ext='obj')
         # notabene: (tismer)
@@ -284,9 +270,7 @@
 
         linkflags = list(self.link_flags)
         if shared:
-            linkflags = self._args_for_shared(linkflags) + [
-                '/EXPORT:$(PYPY_MAIN_FUNCTION)']
-        linkflags += self._exportsymbols_link_flags(eci, relto=path)
+            linkflags = self._args_for_shared(linkflags)
         # Make sure different functions end up at different addresses!
         # This is required for the JIT.
         linkflags.append('/opt:noicf')


More information about the pypy-commit mailing list