bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/31482] New: fail to link static jemalloc with -flto


From: luoxhu at gcc dot gnu.org
Subject: [Bug ld/31482] New: fail to link static jemalloc with -flto
Date: Thu, 14 Mar 2024 06:54:12 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=31482

            Bug ID: 31482
           Summary: fail to link static jemalloc with -flto
           Product: binutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: luoxhu at gcc dot gnu.org
  Target Milestone: ---

For even quite simple test case, the binary fails to link static jemalloc
functions as below when source file is built with -flto either link with bfd.ld
or gold.ld but NOT with mold:

test.cpp:

#include <jemalloc/jemalloc.h>
#include <stdlib.h>

int *ptr;
void test();

void do_something(size_t i) {
   ptr =  (int *)malloc(i * 100);
}

int main(int argc, char **argv) {
  for (size_t i = 0; i < 1000; i++) {
    do_something(i);
  }

  return 0;
}

1) no lto:
g++ test.cpp -c 
g++ test.o /data/home/xionghuluo/install/lib/libjemalloc.a -o test -pthread
-ldl
nm test | grep jemalloc
0000000000414600 T je_jemalloc_postfork_child
00000000004143d0 T je_jemalloc_postfork_parent
0000000000414260 T je_jemalloc_prefork
000000000040e770 t jemalloc_constructor

2) source file -flto:
g++ test.cpp -c -flto
g++ test.o /data/home/xionghuluo/install/lib/libjemalloc.a -o test -pthread
-ldl
nm test | grep jemalloc

3) both source file and libjemalloc are built with LTO, note the difference of
install_s with install for libjemalloc.a:
g++ test.cpp -c -flto
g++ test.o /data/home/xionghuluo/install_s/lib/libjemalloc.a -pthread -ldl -o
test -flto
nm test | grep jemalloc

4) source file is built without flto and libjemalloc is built with LTO:
g++ test.cpp -c
g++ test.o -L/data/home/xionghuluo/install_s/lib -l:libjemalloc.a -pthread -ldl
-o test
nm test | grep jemalloc
0000000000419d10 t je_jemalloc_postfork_child
0000000000419990 t je_jemalloc_postfork_parent
0000000000418f00 t je_jemalloc_prefork
00000000000f6427 N jemalloc.c.50456a62
000000000040e4d0 t jemalloc_constructor


It shows that when the source file test.cpp is built with -flto, no matter
libjemalloc.a is built with or without -flto, the final binary fallback to link
glibc's malloc, is this a valid bug for bfd or golder?  Please take a look,
thanks.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]