But when I inspect the MakeFile of librunt.o in /src/Makefile of the librunt repo, I found that -fPIC is actually enabled when compiling librunt.o. (I also double check in the build log of librunt, -fPIC is truly enabled).
2)build the whole liballocs from scratch in Docker and tried again, same problem occurs.
` make -C src
make[1]: Entering directory '/usr/local/src/libcrunch/src'
LIBALLOCS is /usr/local/src/liballocs
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/include -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/ -c -o libcrunch.o libcrunch.c
In file included from libcrunch_private.h:10:0,
from libcrunch.c:28:
/usr/local/src/liballocs/include/generic_malloc_index.h: In function '__generic_malloc_get_info':
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: implicit declaration of function '__liballocs_extract_and_output_alloc_site_and_type'; did you mean 'extract_and_output_alloc_site_and_type'? [-Wimplicit-function-declaration]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extract_and_output_alloc_site_and_type
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: return makes pointer from integer without a cast [-Wint-conversion]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
heap_info, out_type, (void**) out_site);
libcrunch.c: In function '__is_a_internal':
libcrunch.c:1149:24: warning: implicit declaration of function '__liballocs_get_insert'; did you mean '__liballocs_get_info'? [-Wimplicit-function-declaration]
struct insert *ins = __liballocs_get_insert(NULL, obj);
^~~~~~~~~~~~~~~~~~~~~~
__liballocs_get_info
libcrunch.c:1149:24: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
libcrunch.c: In function 'reinstate_looseness_if_necessary':
libcrunch.c:1707:24: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
struct insert *ins = __liballocs_get_insert(NULL, alloc_start);
^~~~~~~~~~~~~~~~~~~~~~
libcrunch.c: In function '__fetch_bounds_internal':
libcrunch.c:2449:0: warning: "MIN" redefined
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
In file included from libcrunch_private.h:11:0,
from libcrunch.c:28:
/usr/local/src/liballocs/src/liballocs_private.h:216:0: note: this is the location of the previous definition
#define MIN(a, b) ((a)<(b)?(a):(b))
libcrunch.c:2450:0: warning: "MAX" redefined
#define MAX(x, y) (((x) < (y)) ? (y) : (x))
In file included from libcrunch_private.h:11:0,
from libcrunch.c:28:
/usr/local/src/liballocs/src/liballocs_private.h:219:0: note: this is the location of the previous definition
#define MAX(a, b) ((a)>(b)?(a):(b))
In file included from ../include/libcrunch.h:48:0,
from libcrunch.c:27:
libcrunch.c: At top level:
../include/libcrunch_cil_inlines.h:1437:4: warning: 'warnx_pure' is static but used in inline function '__fetch_bounds_from_shadow_space' which is not static
warnx_pure("Fetched invalid bounds for %p (loaded from %p)", ptr, loaded_from);
^~~~~~~~~~
../include/libcrunch_cil_inlines.h:1138:4: warning: 'warnx_pure' is static but used in inline function '__secondary_check_derive_ptr' which is not static
warnx_pure("Went back in bounds at %p: %p (base %p, size %lu)",
^~~~~~~~~~
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -DHAVE_MORECORE=0 -DUSE_DL_PREFIX -fPIC -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/include -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/ -c -o dlmalloc.o /usr/local/src/liballocs/contrib/libsystrap/contrib/dlmalloc.c
ar r "dlmalloc.a" dlmalloc.o
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -shared -o "libcrunch_preload.so" libcrunch.o /usr/local/src/liballocs/lib/liballocs_systrap.o /usr/local/src/liballocs/contrib/libsystrap/lib/libsystrap.a \
-L/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/.libs -Wl,-rpath,/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/.libs -L/usr/local/src/liballocs/lib -L/usr/local/src/liballocs/libsystrap -fno-lto -Wl,-fuse-ld=gold -Wl,--defsym,__libcrunch_bounds_abi_md5sum=0x1ac99f221bc4fc9c -O4 -fno-lto -Bsymbolic -Wl,-O2 -Wl,--wrap,malloc_usable_size -Wl,--wrap,__notify_copy -Wl,--wrap,dlmalloc -Wl,--wrap,dlcalloc -Wl,--wrap,dlfree -Wl,--wrap,dlrealloc -Wl,--wrap,dlmemalign -Wl,--wrap,dlposix_memalign -Wl,--whole-archive dlmalloc.a -Wl,--no-whole-archive -Wl,--defsym,__private_malloc=__wrap_dlmalloc -Wl,--defsym,__private_calloc=__wrap_dlcalloc -Wl,--defsym,__private_free=__wrap_dlfree -Wl,--defsym,__private_realloc=__wrap_dlrealloc -Wl,--defsym,__private_memalign=__wrap_dlmemalign -Wl,--defsym,__private_posix_memalign=__wrap_dlposix_memalign -Wl,--exclude-libs=dlmalloc.a -Bsymbolic -Wl,--wrap,__runt_files_notify_load -Wl,--wrap,__runt_files_notify_unload -Wl,--wrap,__runt_files_metadata_by_addr -Wl,--wrap,__runt_segments_notify_define_segment -Wl,--wrap,__runt_segments_notify_destroy_segment -Wl,--wrap,__runt_sections_notify_define_section -Wl,-O0 -L/usr/local/src/liballocs/contrib/libdlbind/lib /usr/local/src/liballocs/lib/liballocs_preload.a \
-Wl,--no-whole-archive -Wl,-Bdynamic \
-L/usr/local/src/liballocs/contrib/libsystrap/lib -lsystrap -lz -Wl,--no-as-needed -ldl -Wl,--whole-archive /usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/lib/librunt_preload.a -Wl,--no-whole-archive -lunwind -lunwind-x86_64 -ldlbind -ldl
ar r "libcrunch_preload.a" libcrunch.o /usr/local/src/liballocs/lib/liballocs_preload.a
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -fPIC -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/include -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/ -c -o stubs.o stubs.c
In file included from libcrunch_private.h:10:0,
from stubs.c:5:
/usr/local/src/liballocs/include/generic_malloc_index.h: In function '__generic_malloc_get_info':
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: implicit declaration of function '__liballocs_extract_and_output_alloc_site_and_type'; did you mean 'extract_and_output_alloc_site_and_type'? [-Wimplicit-function-declaration]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extract_and_output_alloc_site_and_type
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: return makes pointer from integer without a cast [-Wint-conversion]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
heap_info, out_type, (void**) out_site);
In file included from ../include/libcrunch.h:48:0,
from libcrunch_private.h:15,
from stubs.c:5:
stubs.c: At top level:
../include/libcrunch_cil_inlines.h:1437:4: warning: 'warnx_pure' is static but used in inline function '__fetch_bounds_from_shadow_space' which is not static
warnx_pure("Fetched invalid bounds for %p (loaded from %p)", ptr, loaded_from);
^~~~~~~~~~
../include/libcrunch_cil_inlines.h:1138:4: warning: 'warnx_pure' is static but used in inline function '__secondary_check_derive_ptr' which is not static
warnx_pure("Went back in bounds at %p: %p (base %p, size %lu)",
^~~~~~~~~~
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/include -I/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/ -c -o shadow.o shadow.c
In file included from libcrunch_private.h:10:0,
from shadow.c:22:
/usr/local/src/liballocs/include/generic_malloc_index.h: In function '__generic_malloc_get_info':
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: implicit declaration of function '__liballocs_extract_and_output_alloc_site_and_type'; did you mean 'extract_and_output_alloc_site_and_type'? [-Wimplicit-function-declaration]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extract_and_output_alloc_site_and_type
/usr/local/src/liballocs/include/generic_malloc_index.h:664:35: warning: return makes pointer from integer without a cast [-Wint-conversion]
if (out_type || out_site) return __liballocs_extract_and_output_alloc_site_and_type(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
heap_info, out_type, (void**) out_site);
shadow.c: In function 'check_maps_cb':
shadow.c:74:9: warning: implicit declaration of function 'raw_write'; did you mean 'fwrite'? [-Wimplicit-function-declaration]
else { raw_write(2, "bad mapping address\n", sizeof "bad mapping address\n" - 1); abort(); }
^~~~~~~~~
fwrite
shadow.c: In function 'init_shadow_entries':
shadow.c:333:41: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
*BASE_STORED((void**) __ctype_b_loc()) = *__ctype_b_loc();
^
shadow.c:335:47: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
*BASE_STORED((void**) __ctype_toupper_loc()) = *__ctype_toupper_loc();
^
shadow.c:337:47: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
*BASE_STORED((void**) __ctype_tolower_loc()) = *__ctype_tolower_loc();
^
In file included from ../include/libcrunch.h:48:0,
from shadow.c:21:
shadow.c: At top level:
../include/libcrunch_cil_inlines.h:1437:4: warning: 'warnx_pure' is static but used in inline function '__fetch_bounds_from_shadow_space' which is not static
warnx_pure("Fetched invalid bounds for %p (loaded from %p)", ptr, loaded_from);
^~~~~~~~~~
../include/libcrunch_cil_inlines.h:1138:4: warning: 'warnx_pure' is static but used in inline function '__secondary_check_derive_ptr' which is not static
warnx_pure("Went back in bounds at %p: %p (base %p, size %lu)",
^~~~~~~~~~
In file included from shadow.c:17:0:
/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include/maps.h: In function 'process_one_maps_entry':
/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include/maps.h:266:3: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
write(2, linebuf, strlen(linebuf)+1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc -fPIC -DLIBCRUNCH_LONG_SIZE -DLIBCRUNCH_NO_DENORM_BOUNDS -I/usr/local/src/liballocs/include -I/usr/local/src/liballocs/src -I/usr/local/src/liballocs/contrib/libsystrap/include -I/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/include -I/usr/local/src/liballocs/contrib/libdlbind/include -I/usr/local/src/liballocs/contrib/liballocstool/include -std=gnu99 -g -fPIC -I../include -O3 -fno-lto -ffat-lto-objects -DNDEBUG -DUSE_REAL_LIBUNWIND -Wl,-Map,libcrunch_stubs.so.map -shared -o "libcrunch_stubs.so" stubs.o shadow.o /usr/local/src/liballocs/lib/liballocs_dummyweaks.o /usr/local/src/liballocs/lib/liballocs_systrap.o /usr/local/src/liballocs/contrib/libsystrap/lib/libsystrap.a /usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/lib/librunt.a -L/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/.libs -Wl,-rpath,/usr/local/src/liballocs/contrib/liballocstool/contrib/dwarfidl/contrib/libantlr3c/.libs -L/usr/local/src/liballocs/lib -L/usr/local/src/liballocs/libsystrap -fno-lto -Wl,-fuse-ld=gold -Wl,--whole-archive dlmalloc.a -Wl,--no-whole-archive -Wl,--defsym,__private_malloc=dlmalloc -Wl,--defsym,__private_calloc=dlcalloc -Wl,--defsym,__private_free=dlfree -Wl,--defsym,__private_realloc=dlrealloc -Wl,--defsym,__private_memalign=dlmemalign -Wl,--defsym,__private_posix_memalign=dlposix_memalign -Wl,--exclude-libs=dlmalloc.a -Bsymbolic -Wl,--defsym,__wrap___runt_files_notify_load=__runt_files_notify_load -Wl,--defsym,__wrap___runt_files_notify_unload=__runt_files_notify_unload -Wl,--defsym,__wrap___runt_files_metadata_by_addr=__runt_files_metadata_by_addr -Wl,--defsym,__wrap___runt_segments_notify_define_segment=__runt_segments_notify_define_segment -Wl,--defsym,__wrap___runt_segments_notify_destroy_segment=__runt_segments_notify_destroy_segment -Wl,--defsym,__wrap___runt_sections_notify_define_section=__runt_sections_notify_define_section -L/usr/local/src/liballocs/contrib/libdlbind/lib /usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/lib/librunt.a -lunwind -lunwind-x86_64 -ldlbind -ldl -lz -Wl,--wrap,__liballocs_nudge_mmap -ldlbind
/usr/bin/ld.gold: error: /usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/lib/librunt.a(librunt.o): requires dynamic R_X86_64_PC32 reloc against 'orig_dlopen' which may overflow at runtime; recompile with -fPIC
/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/src/..//src/librunt.c:296: error: undefined reference to 'orig_dlopen'
/usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/src/..//src/librunt.c:298: error: undefined reference to 'orig_dlopen'
collect2: error: ld returned 1 exit status
Makefile:182: recipe for target 'libcrunch_stubs.so' failed
make[1]: *** [libcrunch_stubs.so] Error 1
make[1]: Leaving directory '/usr/local/src/libcrunch/src'
Makefile:5: recipe for target 'src' failed
make: *** [src] Error 2 `
Hi,
I am trying to build libcrunch from a pre-built liballocs. The environment is a docker image built from /liballocs/buildtest/ubuntu-18.04/DockerFile
When I try to build libcrunch, the following problem emerges:
/usr/bin/ld.gold: error: /usr/local/src/liballocs/contrib/libsystrap/contrib/librunt/lib/librunt.a(librunt.o): requires dynamic R_X86_64_PC32 reloc against 'orig_dlopen' which may overflow at runtime; recompile with -fPICBut when I inspect the MakeFile of librunt.o in /src/Makefile of the librunt repo, I found that -fPIC is actually enabled when compiling librunt.o. (I also double check in the build log of librunt, -fPIC is truly enabled).
Here is what I have tried:
2)build the whole liballocs from scratch in Docker and tried again, same problem occurs.
The whole build log of libcrunch can be found here