Merge ~vpa1977/ubuntu/+source/openjdk-20:03_security_release_debug into ubuntu/+source/openjdk-20:ubuntu/devel

Proposed by Vladimir Petko
Status: Merged
Merged at revision: ef884eda32e39c4e1e7100307aff68cf969e7efc
Proposed branch: ~vpa1977/ubuntu/+source/openjdk-20:03_security_release_debug
Merge into: ubuntu/+source/openjdk-20:ubuntu/devel
Prerequisite: ~vpa1977/ubuntu/+source/openjdk-20:02_security_release_update_watch
Diff against target: 119 lines (+47/-32)
3 files modified
debian/JB-jre.overrides.in (+4/-0)
debian/changelog (+2/-0)
debian/rules (+41/-32)
Reviewer Review Type Date Requested Status
Graham Inggs Pending
Matthias Klose Pending
git-ubuntu import Pending
Review via email: mp+442098@code.launchpad.net

Description of the change

Please do not merge, this merge proposal is a part in the series [1][2][3][4]:

Summary of changes:
 - backport openjdk-17 debug symbols/exports fix

PPA: ppa:vpa1977/openjdk-20-april[5]

Testing:
 - it is possible to debug openjdk with and without symbols
 - NMT shows allocation locations

[1] https://code.launchpad.net/~vpa1977/ubuntu/+source/openjdk-20/+git/openjdk-20/+merge/442093
[2] https://code.launchpad.net/~vpa1977/ubuntu/+source/openjdk-20/+git/openjdk-20/+merge/442097
[3] https://code.launchpad.net/~vpa1977/ubuntu/+source/openjdk-20/+git/openjdk-20/+merge/442098
[4] https://code.launchpad.net/~vpa1977/ubuntu/+source/openjdk-20/+git/openjdk-20/+merge/442099
[5] https://launchpad.net/~vpa1977/+archive/ubuntu/openjdk-20-april

To post a comment you must log in.
Revision history for this message
Vladimir Petko (vpa1977) wrote :

Debug without symbols:
--------------------cut-----------------------
gdb java
GNU gdb (Ubuntu 13.1-2ubuntu2) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from java...

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n])
Debuginfod has been disabled.
To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
(No debugging symbols found in java)
(gdb) break JNI_CreateJavaVM
Function "JNI_CreateJavaVM" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (JNI_CreateJavaVM) pending.
(gdb) run -cp . infinite
Starting program: /usr/bin/java -cp . infinite
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7bff6c0 (LWP 7644)]
[Switching to Thread 0x7ffff7bff6c0 (LWP 7644)]

Thread 2 "java" hit Breakpoint 1, 0x00007ffff6f8cdd0 in JNI_CreateJavaVM ()
   from /usr/lib/jvm/java-20-openjdk-amd64/lib/server/libjvm.so
(gdb) where
#0 0x00007ffff6f8cdd0 in JNI_CreateJavaVM ()
   from /usr/lib/jvm/java-20-openjdk-amd64/lib/server/libjvm.so
#1 0x00007ffff7fb2d93 in JavaMain ()
   from /usr/lib/jvm/java-20-openjdk-amd64/bin/../lib/libjli.so
#2 0x00007ffff7fb709d in ThreadJavaMain ()
   from /usr/lib/jvm/java-20-openjdk-amd64/bin/../lib/libjli.so
#3 0x00007ffff7c8f18a in start_thread (arg=<optimized out>)
    at ./nptl/pthread_create.c:444
#4 0x00007ffff7d1dbd0 in clone3 ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) info local
No symbol table info available.
(gdb)
------------------cut-------------------------------------

Revision history for this message
Vladimir Petko (vpa1977) wrote :
Download full text (10.8 KiB)

NMT traces:
---------------------------cut-----------------------
bsp@bsp-Standard-PC-Q35-ICH9-2009:~$ java -XX:NativeMemoryTracking=detail -cp . infinite&
[1] 7772
bsp@bsp-Standard-PC-Q35-ICH9-2009:~$ jcmd 7772 VM.native_memory detail
7772:

Native Memory Tracking:

(Omitting categories weighting less than 1KB)

Total: reserved=2457146KB, committed=127906KB
       malloc: 6690KB #7945
       mmap: reserved=2450456KB, committed=121216KB

- Java Heap (reserved=999424KB, committed=65536KB)
                            (mmap: reserved=999424KB, committed=65536KB)

- Class (reserved=1048635KB, committed=187KB)
                            (classes #518)
                            ( instance classes #431, array classes #87)
                            (malloc=59KB #980)
                            (mmap: reserved=1048576KB, committed=128KB)
                            ( Metadata: )
                            ( reserved=65536KB, committed=128KB)
                            ( used=64KB)
                            ( waste=64KB =49.82%)
                            ( Class space:)
                            ( reserved=1048576KB, committed=128KB)
                            ( used=4KB)
                            ( waste=124KB =97.11%)

- Thread (reserved=18481KB, committed=817KB)
                            (thread #18)
                            (stack: reserved=18432KB, committed=768KB)
                            (malloc=29KB #112)
                            (arena=19KB #34)

- Code (reserved=247729KB, committed=7589KB)
                            (malloc=41KB #820)
                            (mmap: reserved=247688KB, committed=7548KB)

- GC (reserved=58868KB, committed=38804KB)
                            (malloc=4496KB #351)
                            (mmap: reserved=54372KB, committed=34308KB)

- GCCardSet (reserved=15KB, committed=15KB)
                            (malloc=15KB #195)

- Compiler (reserved=167KB, committed=167KB)
                            (malloc=2KB #20)
                            (arena=165KB #5)

- Internal (reserved=197KB, committed=197KB)
                            (malloc=161KB #1410)
                            (mmap: reserved=36KB, committed=36KB)

- Symbol (reserved=1130KB, committed=1130KB)
                            (malloc=770KB #46)
                            (arena=360KB #1)

- Native Memory Tracking (reserved=250KB, committed=250KB)
                            (malloc=126KB #1787)
                            (tracking overhead=124KB)

- Shared class space (reserved=16384KB, committed=12756KB)
                            (mmap: reserved=16384KB, committed=12756KB)

- Arena Chunk (reserved=174KB, committed=174KB)
                            (malloc=174KB #54)

- Module (reserved=39KB, committed=39KB)
                            (malloc=39KB #1212)

- Safepoint (reserved=8KB, committed=8KB)
                            (mmap: reser...

Revision history for this message
Vladimir Petko (vpa1977) wrote :

Debugging with symbols installed:
-----------cut------------
 gdb java
GNU gdb (Ubuntu 13.1-2ubuntu2) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from java...
Reading symbols from /usr/lib/debug/.build-id/53/aa656ed842955b3fccb534e44e7e2a1d7f0fef.debug...
(gdb) break JNI_CreateJavaVM
Function "JNI_CreateJavaVM" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (JNI_CreateJavaVM) pending.
(gdb) run -cp . infinite
Starting program: /usr/bin/java -cp . infinite

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n])
Debuginfod has been disabled.
To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7bff6c0 (LWP 8249)]
[Switching to Thread 0x7ffff7bff6c0 (LWP 8249)]

Thread 2 "java" hit Breakpoint 1, JNI_CreateJavaVM (vm=0x7ffff7bfee60, penv=0x7ffff7bfee68,
    args=0x7ffff7bfee70) at src/hotspot/share/prims/jni.cpp:3704
3704 src/hotspot/share/prims/jni.cpp: No such file or directory.
(gdb) where
#0 JNI_CreateJavaVM (vm=0x7ffff7bfee60, penv=0x7ffff7bfee68, args=0x7ffff7bfee70)
    at src/hotspot/share/prims/jni.cpp:3704
#1 0x00007ffff7fb2d93 in InitializeJVM (ifn=<synthetic pointer>, penv=0x7ffff7bfee68,
    pvm=0x7ffff7bfee60) at src/java.base/share/native/libjli/java.c:1459
#2 JavaMain (_args=<optimized out>) at src/java.base/share/native/libjli/java.c:413
#3 0x00007ffff7fb709d in ThreadJavaMain (args=<optimized out>)
    at src/java.base/unix/native/libjli/java_md.c:650
#4 0x00007ffff7c8f18a in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:444
#5 0x00007ffff7d1dbd0 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) info local
result = -1
(gdb)

-----------------cut-----

symbols table present, exports present

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/JB-jre.overrides.in b/debian/JB-jre.overrides.in
2index c7cb389..679d44c 100644
3--- a/debian/JB-jre.overrides.in
4+++ b/debian/JB-jre.overrides.in
5@@ -1,2 +1,6 @@
6 # these are in the -jre-headless package, -jre depends on it
7 @basename@-jre binary: desktop-command-not-in-package
8+
9+# LP: #2012326 - in order to print allocation locations,
10+# the libraries need to retain symbols
11+@basename@-jre binary: unstripped-binary-or-object
12diff --git a/debian/changelog b/debian/changelog
13index 1424525..b132b7b 100644
14--- a/debian/changelog
15+++ b/debian/changelog
16@@ -7,6 +7,8 @@ openjdk-20 (20.0.1+9~us1-0ubuntu1) UNRELEASED; urgency=medium
17 TODO: waiting for announcement
18 * d/p/*: refresh patches.
19 * d/watch: update version format for the security release.
20+ * d/rules: pack external debug symbols with build-id, do not pack duplicate
21+ symbols, do not strip JVM shared libraries (LP: #2012326, LP: #2016739).
22
23 -- Vladimir Petko <vladimir.petko@canonical.com> Thu, 20 Apr 2023 15:22:10 +1200
24
25diff --git a/debian/rules b/debian/rules
26index fa7c9f1..2febbe5 100755
27--- a/debian/rules
28+++ b/debian/rules
29@@ -1533,15 +1533,45 @@ ifneq (,$(wildcard $(builddir)/$(sdkimg)/lib/*.diz))
30 ) > debian/$(p_dbg).install
31 endif
32
33-# *.debuginfo should be located in /usr/lib/debug/ move files
34+# the logic here -> move external debuginfo files into usr/lib/debug
35+# check binaries and if the debuginfo is found, check if the binary has build id
36+# debug information with build ids is moved under usr/lib/debug/.build-id
37+# since we rewrite the build id with_debugedit=yes, patch the build id inside
38+# the debug symbols file
39+# otherwise (no buildid) just lib debuginfo file where it is
40 mkdir -p $(d)/usr/lib/debug
41 (cd $(d) && find . -path './$(basedir)/*' -name '*.debuginfo' | cpio -pdm usr/lib/debug/)
42 find $(d)/$(basedir)/ -name '*.debuginfo' -exec rm {} \;
43- ( \
44- echo 'usr/lib/debug/$(basedir)/bin/*.debuginfo'; \
45- echo 'usr/lib/debug/$(basedir)/lib/*.debuginfo'; \
46- echo 'usr/lib/debug/$(basedir)/lib/*/*.debuginfo'; \
47- ) > debian/$(p_dbg).install
48+ echo > debian/$(p_dbg).install
49+ for binary in `(cd $(d) && find . -path './$(basedir)/*' -print)`; do \
50+ dir=`dirname $$binary`; \
51+ base=`basename $$binary .so`; \
52+ debuginfo=usr/lib/debug/$$dir/$$base.debuginfo; \
53+ [ -f $(d)/$$debuginfo ] || continue; \
54+ $(OBJCOPY) --compress-debug-sections $(d)/$$debuginfo; \
55+ b_id=$$(LC_ALL=C readelf -n $(d)/$$binary | sed -n 's/ *Build ID: *\([0-9a-f][0-9a-f]*\)/\1/p'); \
56+ if [ -z "$$b_id" ]; then \
57+ echo $$debuginfo >> debian/$(p_dbg).install; \
58+ else \
59+ debugdir=usr/lib/debug/.build-id/$${b_id:0:2}; \
60+ f=$${b_id:2}.debug; \
61+ mkdir -p $(d)/$$debugdir; \
62+ mv $(d)/$$debuginfo $(d)/$$debugdir/$$f; \
63+ chmod 644 $(d)/$$debugdir/$$f; \
64+ echo $$debugdir/$$f >> debian/$(p_dbg).install; \
65+ notes=$$(mktemp); \
66+ $(OBJCOPY) --dump-section=.note.gnu.build-id=$$notes $(d)/$$binary; \
67+ $(OBJCOPY) --update-section=.note.gnu.build-id=$$notes $(d)/$$debugdir/$$f; \
68+ rm $$notes; \
69+ fi; \
70+ if [[ "$(DEB_BUILD_OPTIONS)" != *nostrip* ]]; then \
71+ $(OBJCOPY) --remove-section=.comment --remove-section=.note $(d)/$$binary; \
72+ if [[ "$$binary" != *.so ]]; then \
73+ $(STRIP) --strip-unneeded $(d)/$$binary; \
74+ fi; \
75+ fi; \
76+ done;
77+ find $(d)/usr/lib/debug/ -type d -empty -delete
78
79 # : # FIXME: the targets are not installed ...
80 # rm -rfv $(d)/$(basedir)/lib/jfr
81@@ -1839,33 +1869,12 @@ endif
82 set -e; if command -v dh_strip_nondeterminism >/dev/null; then \
83 dh_strip_nondeterminism -a $(nodemo) $(nojrez); \
84 fi
85- dh_strip -v -a $(nodemo) $(nojrez) \
86- -Xlibjvm.so -X.debuginfo --dbg-package=$(p_dbg)
87+# The strip operation is performed manually, because the build packages
88+# external debug symbols (so that native libraries are included in the modules)
89+# This step would override the actual debug symbols with the empty sections
90+# dh_strip -v -a $(nodemo) $(nojrez) \
91+# -Xlibjvm.so -X.debuginfo --dbg-package=$(p_dbg)
92
93-ifeq (,$(findstring nostrip, $(DEB_BUILD_OPTIONS)))
94- set -ex; \
95- for i in {$(d_jrehl),$(d_jre),$(d_jrez)}/$(basedir)/lib/*/libjvm.so; do \
96- [ -f $$i ] || continue; \
97- b_id=$$(LC_ALL=C readelf -n $$i | sed -n 's/ *Build ID: *\([0-9a-f][0-9a-f]*\)/\1/p'); \
98- if [ -z "$$b_id" ]; then \
99- id=$$(echo $$i | sed -r 's,debian/[^/]+,$(d_dbg)/usr/lib/debug,'); \
100- echo strip $$i; \
101- mkdir -p $$(dirname $$id); \
102- $(OBJCOPY) --only-keep-debug $$i $$id; \
103- chmod 644 $$id; \
104- $(STRIP) --remove-section=.comment --remove-section=.note \
105- --strip-debug $$i; \
106- $(OBJCOPY) --add-gnu-debuglink $$id $$i; \
107- else \
108- d=usr/lib/debug/.build-id/$${b_id:0:2}; \
109- f=$${b_id:2}.debug; \
110- mkdir -p $(d_dbg)/$$d; \
111- $(OBJCOPY) --only-keep-debug --compress-debug-sections $$i $(d_dbg)/$$d/$$f; \
112- chmod 644 $(d_dbg)/$$d/$$f; \
113- $(STRIP) --remove-section=.comment --remove-section=.note $$i; \
114- fi; \
115- done
116-endif
117 dh_compress -a $(nodemo) $(nojrez) -Xexamples -Xdemo -Xpackage-list
118 dh_fixperms -a $(nodemo) $(nojrez)
119 dh_makeshlibs -p$(p_jrehl) -p$(p_jre)

Subscribers

People subscribed via source and target branches