author | sgehwolf |
Thu, 14 Mar 2019 14:04:39 +0100 | |
changeset 54824 | adb3a3aa2e52 |
permissions | -rw-r--r-- |
54824
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
1 |
/* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Red Hat, Inc. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
4 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
10 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
15 |
* accompanied this code). |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
16 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
20 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
23 |
* questions. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
24 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
25 |
package jdk.tools.jlink.internal.plugins; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
26 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
27 |
import java.io.IOException; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
28 |
import java.lang.ProcessBuilder.Redirect; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
29 |
import java.nio.file.FileVisitResult; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
30 |
import java.nio.file.Files; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
31 |
import java.nio.file.InvalidPathException; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
33 |
import java.nio.file.Paths; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
34 |
import java.nio.file.SimpleFileVisitor; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
35 |
import java.nio.file.attribute.BasicFileAttributes; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
36 |
import java.util.ArrayList; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
37 |
import java.util.Arrays; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
38 |
import java.util.HashMap; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
39 |
import java.util.List; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
40 |
import java.util.Locale; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
41 |
import java.util.Map; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
42 |
import java.util.MissingResourceException; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
43 |
import java.util.Objects; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
44 |
import java.util.Optional; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
45 |
import java.util.ResourceBundle; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
46 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
47 |
import jdk.tools.jlink.plugin.Plugin; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
48 |
import jdk.tools.jlink.plugin.PluginException; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
49 |
import jdk.tools.jlink.plugin.ResourcePool; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
50 |
import jdk.tools.jlink.plugin.ResourcePoolBuilder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
51 |
import jdk.tools.jlink.plugin.ResourcePoolEntry; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
52 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
53 |
/** |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
54 |
* Platform specific jlink plugin for stripping debug symbols from native |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
55 |
* libraries and binaries. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
56 |
* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
57 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
58 |
public final class StripNativeDebugSymbolsPlugin implements Plugin { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
59 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
60 |
public static final String NAME = "strip-native-debug-symbols"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
61 |
private static final boolean DEBUG = Boolean.getBoolean("jlink.debug"); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
62 |
private static final String DEFAULT_STRIP_CMD = "objcopy"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
63 |
private static final String STRIP_CMD_ARG = DEFAULT_STRIP_CMD; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
64 |
private static final String KEEP_DEBUG_INFO_ARG = "keep-debuginfo-files"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
65 |
private static final String EXCLUDE_DEBUG_INFO_ARG = "exclude-debuginfo-files"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
66 |
private static final String DEFAULT_DEBUG_EXT = "debuginfo"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
67 |
private static final String STRIP_DEBUG_SYMS_OPT = "-g"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
68 |
private static final String ONLY_KEEP_DEBUG_SYMS_OPT = "--only-keep-debug"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
69 |
private static final String ADD_DEBUG_LINK_OPT = "--add-gnu-debuglink"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
70 |
private static final ResourceBundle resourceBundle; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
71 |
private static final String SHARED_LIBS_EXT = ".so"; // for Linux/Unix |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
72 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
73 |
static { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
74 |
Locale locale = Locale.getDefault(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
75 |
try { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
76 |
resourceBundle = ResourceBundle.getBundle("jdk.tools.jlink." |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
77 |
+ "resources.strip_native_debug_symbols_plugin", locale); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
78 |
} catch (MissingResourceException e) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
79 |
throw new InternalError("Cannot find jlink plugin resource bundle (" + |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
80 |
NAME + ") for locale " + locale); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
81 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
82 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
83 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
84 |
private final ObjCopyCmdBuilder cmdBuilder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
85 |
private boolean includeDebugSymbols; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
86 |
private String stripBin; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
87 |
private String debuginfoExt; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
88 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
89 |
public StripNativeDebugSymbolsPlugin() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
90 |
this(new DefaultObjCopyCmdBuilder()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
91 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
92 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
93 |
public StripNativeDebugSymbolsPlugin(ObjCopyCmdBuilder cmdBuilder) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
94 |
this.cmdBuilder = cmdBuilder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
95 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
96 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
97 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
98 |
public String getName() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
99 |
return NAME; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
100 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
101 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
102 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
103 |
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
104 |
StrippedDebugInfoBinaryBuilder builder = new StrippedDebugInfoBinaryBuilder( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
105 |
includeDebugSymbols, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
106 |
debuginfoExt, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
107 |
cmdBuilder, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
108 |
stripBin); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
109 |
in.transformAndCopy((resource) -> { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
110 |
ResourcePoolEntry res = resource; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
111 |
if ((resource.type() == ResourcePoolEntry.Type.NATIVE_LIB && |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
112 |
resource.path().endsWith(SHARED_LIBS_EXT)) || |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
113 |
resource.type() == ResourcePoolEntry.Type.NATIVE_CMD) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
114 |
Optional<StrippedDebugInfoBinary> strippedBin = builder.build(resource); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
115 |
if (strippedBin.isPresent()) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
116 |
StrippedDebugInfoBinary sb = strippedBin.get(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
117 |
res = sb.strippedBinary(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
118 |
if (includeDebugSymbols) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
119 |
Optional<ResourcePoolEntry> debugInfo = sb.debugSymbols(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
120 |
if (debugInfo.isEmpty()) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
121 |
String key = NAME + ".error.debugfile"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
122 |
logError(resource, key); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
123 |
} else { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
124 |
out.add(debugInfo.get()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
125 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
126 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
127 |
} else { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
128 |
String key = NAME + ".error.file"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
129 |
logError(resource, key); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
130 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
131 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
132 |
return res; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
133 |
}, out); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
134 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
135 |
return out.build(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
136 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
137 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
138 |
private void logError(ResourcePoolEntry resource, String msgKey) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
139 |
String msg = PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
140 |
msgKey, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
141 |
NAME, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
142 |
resource.path()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
143 |
System.err.println(msg); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
144 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
145 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
146 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
147 |
public Category getType() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
148 |
return Category.TRANSFORMER; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
149 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
150 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
151 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
152 |
public String getDescription() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
153 |
String key = NAME + ".description"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
154 |
return PluginsResourceBundle.getMessage(resourceBundle, key); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
155 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
156 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
157 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
158 |
public boolean hasArguments() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
159 |
return true; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
160 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
161 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
162 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
163 |
public String getArgumentsDescription() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
164 |
String key = NAME + ".argument"; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
165 |
return PluginsResourceBundle.getMessage(resourceBundle, key); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
166 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
167 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
168 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
169 |
public void configure(Map<String, String> config) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
170 |
doConfigure(true, config); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
171 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
172 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
173 |
// For testing so that validation can be turned off |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
174 |
public void doConfigure(boolean withChecks, Map<String, String> orig) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
175 |
Map<String, String> config = new HashMap<>(orig); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
176 |
String arg = config.remove(NAME); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
177 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
178 |
stripBin = DEFAULT_STRIP_CMD; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
179 |
debuginfoExt = DEFAULT_DEBUG_EXT; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
180 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
181 |
// argument must never be null as it requires at least one |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
182 |
// argument, since hasArguments() == true. This might change once |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
183 |
// 8218761 is implemented. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
184 |
if (arg == null) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
185 |
throw new InternalError(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
186 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
187 |
boolean hasOmitDebugInfo = false; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
188 |
boolean hasKeepDebugInfo = false; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
189 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
190 |
if (KEEP_DEBUG_INFO_ARG.equals(arg)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
191 |
// Case: --strip-native-debug-symbols keep-debuginfo-files |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
192 |
hasKeepDebugInfo = true; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
193 |
} else if (arg.startsWith(KEEP_DEBUG_INFO_ARG)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
194 |
// Case: --strip-native-debug-symbols keep-debuginfo-files=foo |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
195 |
String[] tokens = arg.split("="); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
196 |
if (tokens.length != 2 || !KEEP_DEBUG_INFO_ARG.equals(tokens[0])) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
197 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
198 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
199 |
NAME + ".iae", NAME, arg)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
200 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
201 |
hasKeepDebugInfo = true; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
202 |
debuginfoExt = tokens[1]; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
203 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
204 |
if (EXCLUDE_DEBUG_INFO_ARG.equals(arg) || arg.startsWith(EXCLUDE_DEBUG_INFO_ARG + "=")) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
205 |
// Case: --strip-native-debug-symbols exclude-debuginfo-files[=something] |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
206 |
hasOmitDebugInfo = true; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
207 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
208 |
if (arg.startsWith(STRIP_CMD_ARG)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
209 |
// Case: --strip-native-debug-symbols objcopy=<path/to/objcopy |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
210 |
String[] tokens = arg.split("="); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
211 |
if (tokens.length != 2 || !STRIP_CMD_ARG.equals(tokens[0])) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
212 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
213 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
214 |
NAME + ".iae", NAME, arg)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
215 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
216 |
if (withChecks) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
217 |
validateStripArg(tokens[1]); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
218 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
219 |
stripBin = tokens[1]; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
220 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
221 |
// Cases (combination of options): |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
222 |
// --strip-native-debug-symbols keep-debuginfo-files:objcopy=</objcpy/path> |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
223 |
// --strip-native-debug-symbols keep-debuginfo-files=ext:objcopy=</objcpy/path> |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
224 |
// --strip-native-debug-symbols exclude-debuginfo-files:objcopy=</objcpy/path> |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
225 |
String stripArg = config.remove(STRIP_CMD_ARG); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
226 |
if (stripArg != null && withChecks) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
227 |
validateStripArg(stripArg); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
228 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
229 |
if (stripArg != null) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
230 |
stripBin = stripArg; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
231 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
232 |
// Case (reversed combination) |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
233 |
// --strip-native-debug-symbols objcopy=</objcpy/path>:keep-debuginfo-files=ext |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
234 |
// Note: cases like the following are not allowed by the parser |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
235 |
// --strip-native-debug-symbols objcopy=</objcpy/path>:keep-debuginfo-files |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
236 |
// --strip-native-debug-symbols objcopy=</objcpy/path>:exclude-debuginfo-files |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
237 |
String keepDebugInfo = config.remove(KEEP_DEBUG_INFO_ARG); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
238 |
if (keepDebugInfo != null) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
239 |
hasKeepDebugInfo = true; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
240 |
debuginfoExt = keepDebugInfo; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
241 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
242 |
if ((hasKeepDebugInfo || includeDebugSymbols) && hasOmitDebugInfo) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
243 |
// Cannot keep and omit debug info at the same time. Note that |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
244 |
// includeDebugSymbols might already be true if configure is being run |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
245 |
// on the same plugin instance multiple times. Plugin option can |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
246 |
// repeat. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
247 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
248 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
249 |
NAME + ".iae.conflict", |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
250 |
NAME, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
251 |
EXCLUDE_DEBUG_INFO_ARG, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
252 |
KEEP_DEBUG_INFO_ARG)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
253 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
254 |
if (!arg.startsWith(STRIP_CMD_ARG) && |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
255 |
!arg.startsWith(KEEP_DEBUG_INFO_ARG) && |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
256 |
!arg.startsWith(EXCLUDE_DEBUG_INFO_ARG)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
257 |
// unknown arg value; case --strip-native-debug-symbols foobar |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
258 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
259 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
260 |
NAME + ".iae", NAME, arg)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
261 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
262 |
if (!config.isEmpty()) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
263 |
// extraneous values; --strip-native-debug-symbols keep-debuginfo-files:foo=bar |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
264 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
265 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
266 |
NAME + ".iae", NAME, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
267 |
config.toString())); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
268 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
269 |
includeDebugSymbols = hasKeepDebugInfo; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
270 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
271 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
272 |
private void validateStripArg(String stripArg) throws IllegalArgumentException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
273 |
try { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
274 |
Path strip = Paths.get(stripArg); // verify it's a resonable path |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
275 |
if (!Files.isExecutable(strip)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
276 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
277 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
278 |
NAME + ".invalidstrip", |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
279 |
stripArg)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
280 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
281 |
} catch (InvalidPathException e) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
282 |
throw new IllegalArgumentException( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
283 |
PluginsResourceBundle.getMessage(resourceBundle, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
284 |
NAME + ".invalidstrip", |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
285 |
e.getInput())); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
286 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
287 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
288 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
289 |
private static class StrippedDebugInfoBinaryBuilder { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
290 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
291 |
private final boolean includeDebug; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
292 |
private final String debugExt; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
293 |
private final ObjCopyCmdBuilder cmdBuilder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
294 |
private final String strip; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
295 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
296 |
private StrippedDebugInfoBinaryBuilder(boolean includeDebug, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
297 |
String debugExt, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
298 |
ObjCopyCmdBuilder cmdBuilder, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
299 |
String strip) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
300 |
this.includeDebug = includeDebug; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
301 |
this.debugExt = debugExt; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
302 |
this.cmdBuilder = cmdBuilder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
303 |
this.strip = strip; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
304 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
305 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
306 |
private Optional<StrippedDebugInfoBinary> build(ResourcePoolEntry resource) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
307 |
Path tempDir = null; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
308 |
Optional<ResourcePoolEntry> debugInfo = Optional.empty(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
309 |
try { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
310 |
Path resPath = Paths.get(resource.path()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
311 |
String relativeFileName = resPath.getFileName().toString(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
312 |
tempDir = Files.createTempDirectory(NAME + relativeFileName); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
313 |
Path resourceFileBinary = tempDir.resolve(relativeFileName); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
314 |
String relativeDbgFileName = relativeFileName + "." + debugExt; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
315 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
316 |
Files.write(resourceFileBinary, resource.contentBytes()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
317 |
Path resourceFileDebugSymbols; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
318 |
if (includeDebug) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
319 |
resourceFileDebugSymbols = tempDir.resolve(Paths.get(relativeDbgFileName)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
320 |
String debugEntryPath = resource.path() + "." + debugExt; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
321 |
byte[] debugInfoBytes = createDebugSymbolsFile(resourceFileBinary, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
322 |
resourceFileDebugSymbols, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
323 |
relativeDbgFileName); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
324 |
if (debugInfoBytes != null) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
325 |
ResourcePoolEntry debugEntry = ResourcePoolEntry.create( |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
326 |
debugEntryPath, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
327 |
resource.type(), |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
328 |
debugInfoBytes); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
329 |
debugInfo = Optional.of(debugEntry); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
330 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
331 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
332 |
if (!stripBinary(resourceFileBinary)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
333 |
if (DEBUG) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
334 |
System.err.println("DEBUG: Stripping debug info failed."); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
335 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
336 |
return Optional.empty(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
337 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
338 |
if (includeDebug && !addGnuDebugLink(tempDir, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
339 |
relativeFileName, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
340 |
relativeDbgFileName)) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
341 |
if (DEBUG) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
342 |
System.err.println("DEBUG: Creating debug link failed."); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
343 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
344 |
return Optional.empty(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
345 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
346 |
byte[] strippedBytes = Files.readAllBytes(resourceFileBinary); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
347 |
ResourcePoolEntry strippedResource = resource.copyWithContent(strippedBytes); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
348 |
return Optional.of(new StrippedDebugInfoBinary(strippedResource, debugInfo)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
349 |
} catch (IOException | InterruptedException e) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
350 |
throw new PluginException(e); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
351 |
} finally { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
352 |
if (tempDir != null) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
353 |
deleteDirRecursivelyIgnoreResult(tempDir); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
354 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
355 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
356 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
357 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
358 |
/* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
359 |
* Equivalent of 'objcopy -g binFile'. Returning true iff stripping of the binary |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
360 |
* succeeded. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
361 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
362 |
private boolean stripBinary(Path binFile) |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
363 |
throws InterruptedException, IOException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
364 |
String filePath = binFile.toAbsolutePath().toString(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
365 |
List<String> stripCmdLine = cmdBuilder.build(strip, STRIP_DEBUG_SYMS_OPT, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
366 |
filePath); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
367 |
ProcessBuilder builder = createProcessBuilder(stripCmdLine); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
368 |
Process stripProc = builder.start(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
369 |
int retval = stripProc.waitFor(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
370 |
return retval == 0; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
371 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
372 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
373 |
/* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
374 |
* Equivalent of 'objcopy --add-gnu-debuglink=relativeDbgFileName binFile'. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
375 |
* Returning true iff adding the debug link succeeded. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
376 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
377 |
private boolean addGnuDebugLink(Path currDir, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
378 |
String binFile, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
379 |
String relativeDbgFileName) |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
380 |
throws InterruptedException, IOException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
381 |
List<String> addDbgLinkCmdLine = cmdBuilder.build(strip, ADD_DEBUG_LINK_OPT + |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
382 |
"=" + relativeDbgFileName, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
383 |
binFile); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
384 |
ProcessBuilder builder = createProcessBuilder(addDbgLinkCmdLine); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
385 |
builder.directory(currDir.toFile()); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
386 |
Process stripProc = builder.start(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
387 |
int retval = stripProc.waitFor(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
388 |
return retval == 0; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
389 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
390 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
391 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
392 |
/* |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
393 |
* Equivalent of 'objcopy --only-keep-debug binPath debugPath'. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
394 |
* Returning the bytes of the file containing debug symbols. |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
395 |
*/ |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
396 |
private byte[] createDebugSymbolsFile(Path binPath, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
397 |
Path debugPath, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
398 |
String dbgFileName) throws InterruptedException, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
399 |
IOException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
400 |
String filePath = binPath.toAbsolutePath().toString(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
401 |
String dbgPath = debugPath.toAbsolutePath().toString(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
402 |
List<String> createLinkCmdLine = cmdBuilder.build(strip, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
403 |
ONLY_KEEP_DEBUG_SYMS_OPT, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
404 |
filePath, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
405 |
dbgPath); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
406 |
ProcessBuilder builder = createProcessBuilder(createLinkCmdLine); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
407 |
Process stripProc = builder.start(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
408 |
int retval = stripProc.waitFor(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
409 |
if (retval != 0) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
410 |
if (DEBUG) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
411 |
System.err.println("DEBUG: Creating debuginfo file failed."); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
412 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
413 |
return null; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
414 |
} else { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
415 |
return Files.readAllBytes(debugPath); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
416 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
417 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
418 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
419 |
private ProcessBuilder createProcessBuilder(List<String> cmd) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
420 |
ProcessBuilder builder = new ProcessBuilder(cmd); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
421 |
builder.redirectError(Redirect.INHERIT); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
422 |
builder.redirectOutput(Redirect.INHERIT); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
423 |
return builder; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
424 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
425 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
426 |
private void deleteDirRecursivelyIgnoreResult(Path tempDir) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
427 |
try { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
428 |
Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
429 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
430 |
public FileVisitResult visitFile(Path file, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
431 |
BasicFileAttributes attrs) throws IOException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
432 |
Files.delete(file); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
433 |
return FileVisitResult.CONTINUE; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
434 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
435 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
436 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
437 |
public FileVisitResult postVisitDirectory(Path dir, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
438 |
IOException exc) throws IOException { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
439 |
Files.delete(dir); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
440 |
return FileVisitResult.CONTINUE; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
441 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
442 |
}); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
443 |
} catch (IOException e) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
444 |
// ignore deleting the temp dir |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
445 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
446 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
447 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
448 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
449 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
450 |
private static class StrippedDebugInfoBinary { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
451 |
private final ResourcePoolEntry strippedBinary; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
452 |
private final Optional<ResourcePoolEntry> debugSymbols; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
453 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
454 |
private StrippedDebugInfoBinary(ResourcePoolEntry strippedBinary, |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
455 |
Optional<ResourcePoolEntry> debugSymbols) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
456 |
this.strippedBinary = Objects.requireNonNull(strippedBinary); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
457 |
this.debugSymbols = Objects.requireNonNull(debugSymbols); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
458 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
459 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
460 |
public ResourcePoolEntry strippedBinary() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
461 |
return strippedBinary; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
462 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
463 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
464 |
public Optional<ResourcePoolEntry> debugSymbols() { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
465 |
return debugSymbols; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
466 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
467 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
468 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
469 |
// For better testing using mocked objcopy |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
470 |
public static interface ObjCopyCmdBuilder { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
471 |
List<String> build(String objCopy, String...options); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
472 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
473 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
474 |
private static final class DefaultObjCopyCmdBuilder implements ObjCopyCmdBuilder { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
475 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
476 |
@Override |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
477 |
public List<String> build(String objCopy, String...options) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
478 |
List<String> cmdList = new ArrayList<>(); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
479 |
cmdList.add(objCopy); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
480 |
if (options.length > 0) { |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
481 |
cmdList.addAll(Arrays.asList(options)); |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
482 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
483 |
return cmdList; |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
484 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
485 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
486 |
} |
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
487 |
|
adb3a3aa2e52
8214796: Create a jlink plugin for stripping debug info symbols from native libraries
sgehwolf
parents:
diff
changeset
|
488 |
} |