[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] Fix undefined reference to __dso_handle problem encountered with librt.so



[Please CC me on any responses]

When using mklibs on a simple test application I encountered the following error
when mklibs attempts to build a reduced librt.so:

/usr/lib64/libpthread_nonshared.a(pthread_atfork.oS): relocation R_X86_64_PC32
against undefined hidden symbol `__dso_handle' can not be used when making a
shared object
ld: final link failed: Bad value

Examining the link map for librt.so, when built by EGLIBC, I see the
__dso_handle definition used by it comes from crtbeginS.o, which isn't included
in the link because mklibs passes -nostartfiles.

In order to create a reduced librt.so that as closely as possible resembles the
original, it makes sense to include crtbeginS.o when dealing with librt.so.1.
This patch does that. crtendS.o is included as a requisite of crtbeginS.o.

Joe

diff --git a/src/mklibs b/src/mklibs
index 14ca02a..0b62136 100755
--- a/src/mklibs
+++ b/src/mklibs
@@ -617,6 +617,17 @@ while 1:
                 extra_post_obj.append(sysroot + libc_extras_dir + "/sofini.o")
                 symbols.add(ProvidedSymbol('__dso_handle', None, None, True))

+            if soname in ("librt.so.1"):
+                crtbegin = command(target + "gcc",
+                                   " ".join(gcc_options),
+                                   "-print-file-name=crtbeginS.o");
+                crtend = command(target + "gcc",
+                                 " ".join(gcc_options),
+                                 "-print-file-name=crtendS.o");
+                extra_pre_obj.append(" ".join(crtbegin))
+                extra_post_obj.append(" ".join(crtend))
+                symbols.add(ProvidedSymbol('__dso_handle', None, None, True))
+
             map_file = find_pic_map(library)
             if map_file:
                 extra_flags.append("-Wl,--version-script=" + map_file)


Reply to: