core.internal.elf: Improve usability#2983
Conversation
|
Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#2983" |
| printf("not mapped into memory\n"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
E.g.:
section 0 not mapped into memory
section 1 .interp 0x55a0f1d27270 - 0x55a0f1d2728c
section 2 .note.ABI-tag 0x55a0f1d2728c - 0x55a0f1d272ac
section 3 .note.gnu.build-id 0x55a0f1d272ac - 0x55a0f1d272d0
section 4 .gnu.hash 0x55a0f1d272d0 - 0x55a0f1d273b0
section 5 .dynsym 0x55a0f1d273b0 - 0x55a0f1d278d8
section 6 .dynstr 0x55a0f1d278d8 - 0x55a0f1d280da
section 7 .gnu.version 0x55a0f1d280da - 0x55a0f1d28148
section 8 .gnu.version_r 0x55a0f1d28148 - 0x55a0f1d281a8
section 9 .rela.dyn 0x55a0f1d281a8 - 0x55a0f1d28358
section 10 .rela.plt 0x55a0f1d28358 - 0x55a0f1d284f0
section 11 .init 0x55a0f1d284f0 - 0x55a0f1d28507
section 12 .plt 0x55a0f1d28510 - 0x55a0f1d28630
section 13 .plt.got 0x55a0f1d28630 - 0x55a0f1d28638
section 14 .text 0x55a0f1d28640 - 0x55a0f1d28d72
section 15 .fini 0x55a0f1d28d74 - 0x55a0f1d28d7d
section 16 .rodata 0x55a0f1d28d80 - 0x55a0f1d28df0
section 17 .eh_frame_hdr 0x55a0f1d28df0 - 0x55a0f1d28e9c
section 18 .eh_frame 0x55a0f1d28ea0 - 0x55a0f1d291d8
section 19 .gcc_except_table 0x55a0f1d291d8 - 0x55a0f1d291f8
section 20 .tbss 0x55a0f1f29cd8 - 0x55a0f1f29ce8
section 21 .init_array 0x55a0f1f29cd8 - 0x55a0f1f29ce8
section 22 .fini_array 0x55a0f1f29ce8 - 0x55a0f1f29cf8
section 23 .dynamic 0x55a0f1f29cf8 - 0x55a0f1f29f28
section 24 .got 0x55a0f1f29f28 - 0x55a0f1f2a000
section 25 .data 0x55a0f1f2a000 - 0x55a0f1f2a058
section 26 __minfo 0x55a0f1f2a058 - 0x55a0f1f2a060
section 27 .bss 0x55a0f1f2a060 - 0x55a0f1f2a070
section 28 .comment not mapped into memory
section 29 .symtab not mapped into memory
section 30 .strtab not mapped into memory
section 31 .shstrtab not mapped into memory
| printf(" path: %s\n", path ? path.ptr : ""); | ||
| printf(" base: %p\n", object.baseAddress); | ||
| } | ||
| } |
There was a problem hiding this comment.
E.g.:
DSO name: runtime/druntime-test-runner-shared
path: /home/martin/build-ldc/runtime/druntime-test-runner-shared
base: 0x5589831e6000
DSO name: linux-vdso.so.1
path: [vdso]
base: 0x7ffdeb9f7000
DSO name: /home/martin/build-ldc/lib/libdruntime-ldc-unittest-shared.so.91
path: /home/martin/build-ldc/lib/libdruntime-ldc-unittest-shared.so.2.0.91
base: 0x7ff21166b000
DSO name: /lib/x86_64-linux-gnu/libgcc_s.so.1
path: /lib/x86_64-linux-gnu/libgcc_s.so.1
base: 0x7ff211453000
DSO name: /lib/x86_64-linux-gnu/libc.so.6
path: /lib/x86_64-linux-gnu/libc-2.27.so
base: 0x7ff211062000
DSO name: /lib64/ld-linux-x86-64.so.2
path: /lib/x86_64-linux-gnu/ld-2.27.so
base: 0x7ff211b53000
DSO name: /lib/x86_64-linux-gnu/libm.so.6
path: /lib/x86_64-linux-gnu/libm-2.27.so
base: 0x7ff210cc4000
DSO name: /lib/x86_64-linux-gnu/libpthread.so.0
path: /lib/x86_64-linux-gnu/libpthread-2.27.so
base: 0x7ff210aa5000
DSO name: /lib/x86_64-linux-gnu/librt.so.1
path: /lib/x86_64-linux-gnu/librt-2.27.so
base: 0x7ff21089d000
DSO name: /lib/x86_64-linux-gnu/libdl.so.2
path: /lib/x86_64-linux-gnu/libdl-2.27.so
base: 0x7ff210699000
| * Tries to find the index of the section with the specified name. | ||
| * Returns: -1 if not found, otherwise 0-based section index. | ||
| */ | ||
| size_t findSectionIndexByName(const(char)[] sectionName) const |
There was a problem hiding this comment.
This function has been removed. These modules have just been added with v2.091 (#2330); at the time I originally worked on this (~1.5 years ago), there was no move in druntime (only in Phobos), so I've resorted to this little helper for findSectionHeaderByName().
| { | ||
| const name = object.name(); | ||
| assert(name.length); | ||
| const path = object.getPath(buffer); |
There was a problem hiding this comment.
I've originally asserted that path isn't null (no error), but that failed for some Linux CI systems for LDC. I haven't bothered looking into what the issue is.
Geod24
left a comment
There was a problem hiding this comment.
Nice change. Since the unittests output something, can they be made integration tests ?
src/core/internal/elf/dl.d
Outdated
| private @nogc nothrow: | ||
|
|
||
| version (linux) | ||
| version (CRuntime_Bionic) |
There was a problem hiding this comment.
So __USE_GNU is true unconditionally, which means program_invocation_name from core.sys.linux.errno is also available when compiling for Android. Should one of those be guarded by a version ?
There was a problem hiding this comment.
Heh, I was a bit lazy and took this workaround from the guy who tested this stuff. I'll try to get ahold of the Android NDK headers and check,
There was a problem hiding this comment.
By the looks of it, __USE_GNU etc. is defined for most Linux C libs in https://github.com/dlang/druntime/blob/master/src/core/sys/posix/config.d (notable exception: version(CRuntime_Musl)), incl. being false for Android/Bionic. The uncoditional enums in core.sys.linux.config (publicly importing core.sys.posix.config but 'overriding' with unconditional enums, apparently from glibc) seem wrong and obsolete. I guess the proper fix would be to make sure all expected enums are already set up in the Posix module, for all Linux C libs.
There was a problem hiding this comment.
That looks like a dangerous change though (I've just seen that __USE_GNU is false for glibc in ...posix.config!), so I don't want to add it in this PR. I'll add a TODO comment here.
|
|
||
| char[N + 128] lineBuffer = void; | ||
|
|
||
| snprintf(lineBuffer.ptr, lineBuffer.length, "/proc/%d/maps", getpid()); |
There was a problem hiding this comment.
In FreeBSD, using kinfo_getvmmap seems more suitable, this works even if /proc is not mounted.
https://www.freebsd.org/cgi/man.cgi?query=kinfo_getvmmap
There was a problem hiding this comment.
I'm not sure that's worth it (incl. the libutil dependency); I've just tried to write this in a portable way (e.g., no /proc/self/maps etc.).
You mean a test with Makefile etc. in the |
As alternative to get ahold of the ELF file path in case name() doesn't return a full path.
…med sections E.g., this allows to conveniently scan for multiple named sections in a single pass.
Paving the way for a revamped
rt.sections_androidcoming up next (ldc-developers#178).