qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yonggang Luo <luoyonggang@gmail.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Yonggang Luo <luoyonggang@gmail.com>
Subject: [PATCH 2/6] meson: Convert undefsym.sh to undefsym.py
Date: Thu,  3 Sep 2020 01:00:50 +0800	[thread overview]
Message-ID: <20200902170054.810-3-luoyonggang@gmail.com> (raw)
In-Reply-To: <20200902170054.810-1-luoyonggang@gmail.com>

undefsym.sh are not msys2 compatible, convert it to python script

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 meson.build         |  2 +-
 scripts/undefsym.py | 57 +++++++++++++++++++++++++++++++++++++++++++++
 scripts/undefsym.sh | 20 ----------------
 3 files changed, 58 insertions(+), 21 deletions(-)
 create mode 100644 scripts/undefsym.py
 delete mode 100755 scripts/undefsym.sh

diff --git a/meson.build b/meson.build
index 55c7d2318c..c9f5d05664 100644
--- a/meson.build
+++ b/meson.build
@@ -863,7 +863,7 @@ foreach d, list : modules
 endforeach
 
 nm = find_program('nm')
-undefsym = find_program('scripts/undefsym.sh')
+undefsym = find_program('scripts/undefsym.py')
 block_syms = custom_target('block.syms', output: 'block.syms',
                              input: [libqemuutil, block_mods],
                              capture: true,
diff --git a/scripts/undefsym.py b/scripts/undefsym.py
new file mode 100644
index 0000000000..c690f88c7a
--- /dev/null
+++ b/scripts/undefsym.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# Before a shared module's DSO is produced, a static library is built for it
+# and passed to this script.  The script generates -Wl,-u options to force
+# the inclusion of symbol from libqemuutil.a if the shared modules need them,
+# This is necessary because the modules may use functions not needed by the
+# executable itself, which would cause the function to not be linked in.
+# Then the DSO loading would fail because of the missing symbol.
+
+
+"""
+Compare the static library with the shared module for compute the symbol duplication
+"""
+
+import sys
+import subprocess
+
+def filter_lines_set(stdout, is_static = True):
+    linesSet = set()
+    for line in stdout.splitlines():
+        tokens = line.split(b' ')
+        if len(tokens) >= 1:
+            if len(tokens) > 1:
+                if is_static and tokens[1] == b'U':
+                    continue
+                if not is_static and tokens[1] != b'U':
+                    continue
+            new_line = b'-Wl,-u,' + tokens[0]
+            if not new_line in linesSet:
+                linesSet.add(new_line)
+    return linesSet
+
+def main(args):
+    if len(args) <= 3:
+        sys.exit(0)
+
+    nm = args[1]
+    staticlib = args[2]
+    pc = subprocess.run([nm, "-P", "-g", staticlib], stdout=subprocess.PIPE)
+    if pc.returncode != 0:
+        sys.exit(-1)
+    lines_set_left = filter_lines_set(pc.stdout)
+
+    shared_modules = args[3:]
+    pc = subprocess.run([nm, "-P", "-g"] + shared_modules, stdout=subprocess.PIPE)
+    if pc.returncode != 0:
+        sys.exit(-1)
+    lines_set_right = filter_lines_set(pc.stdout, False)
+    lines = []
+    for line in sorted(list(lines_set_right)):
+        if line in lines_set_left:
+            lines.append(line)
+    sys.stdout.write(b'\n'.join(lines).decode())
+
+if __name__ == "__main__":
+    main(sys.argv)
diff --git a/scripts/undefsym.sh b/scripts/undefsym.sh
deleted file mode 100755
index b9ec332e95..0000000000
--- a/scripts/undefsym.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#! /usr/bin/env bash
-
-# Before a shared module's DSO is produced, a static library is built for it
-# and passed to this script.  The script generates -Wl,-u options to force
-# the inclusion of symbol from libqemuutil.a if the shared modules need them,
-# This is necessary because the modules may use functions not needed by the
-# executable itself, which would cause the function to not be linked in.
-# Then the DSO loading would fail because of the missing symbol.
-
-if test $# -le 2; then
-  exit 0
-fi
-
-NM=$1
-staticlib=$2
-shift 2
-# Find symbols defined in static libraries and undefined in shared modules
-comm -12 \
-  <( $NM -P -g $staticlib | awk '$2!="U"{print "-Wl,-u," $1}' | sort -u) \
-  <( $NM -P -g "$@" | awk '$2=="U"{print "-Wl,-u," $1}' | sort -u)
-- 
2.27.0.windows.1



  parent reply	other threads:[~2020-09-02 17:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 17:00 [PATCH 0/6] Green the msys2 CI make Yonggang Luo
2020-09-02 17:00 ` [PATCH 1/6] configure: fixes dtc not cloned when running msys2 CI Yonggang Luo
2020-09-02 17:32   ` Philippe Mathieu-Daudé
2020-09-02 17:00 ` Yonggang Luo [this message]
2020-09-02 17:00 ` [PATCH 3/6] ci: Install msys2 in a proper way refer to https://github.com/cirruslabs/cirrus-ci-docs/issues/699 Enable msys2 ci in cirrus Yonggang Luo
2020-09-02 17:30   ` Philippe Mathieu-Daudé
2020-09-02 17:42     ` 罗勇刚(Yonggang Luo)
2020-09-02 19:31       ` Philippe Mathieu-Daudé
2020-09-02 19:32         ` 罗勇刚(Yonggang Luo)
2020-09-02 17:50     ` 罗勇刚(Yonggang Luo)
2020-09-02 18:54       ` Mark Cave-Ayland
2020-09-02 18:56         ` 罗勇刚(Yonggang Luo)
2020-09-02 19:00           ` Mark Cave-Ayland
2020-09-02 19:01             ` 罗勇刚(Yonggang Luo)
2020-09-02 19:13               ` Mark Cave-Ayland
2020-09-02 19:15                 ` 罗勇刚(Yonggang Luo)
2020-09-02 18:50     ` Mark Cave-Ayland
2020-09-02 17:00 ` [PATCH 4/6] tcg: Fixes dup_const link error Yonggang Luo
2020-09-02 17:16   ` Richard Henderson
2020-09-02 17:17     ` 罗勇刚(Yonggang Luo)
2020-09-02 17:21       ` Richard Henderson
2020-09-02 17:00 ` [PATCH 5/6] tests: handling signal on win32 properly Yonggang Luo
2020-09-02 17:04   ` Paolo Bonzini
2020-09-02 17:09     ` 罗勇刚(Yonggang Luo)
2020-09-03  5:58     ` Thomas Huth
2020-09-03  7:00       ` Paolo Bonzini
2020-09-02 17:00 ` [PATCH 6/6] configure: Fix include and linkage issue on msys2 Yonggang Luo
2020-09-02 17:05   ` Paolo Bonzini
2020-09-02 17:06     ` 罗勇刚(Yonggang Luo)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200902170054.810-3-luoyonggang@gmail.com \
    --to=luoyonggang@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).