NVIDIA / cuda-gdb

CUDA GDB
GNU General Public License v2.0
185 stars 56 forks source link

Wrong position of -lpthread in linker command #2

Closed dmikushin closed 1 year ago

dmikushin commented 7 years ago

Configured 7.5 branch with:

$ ../configure --prefix=$(pwd)/../install --program-prefix=cuda- --enable-cuda --enable-targets="x86_64-unknown-linux-gnu" CFLAGS='-I/opt/cuda/include' LDFLAGS='-lpthread'

Fails to link the gdb executable during the build process:

$ gcc -I/opt/cuda/include   -static-libstdc++ -static-libgcc -lpthread   \
        -o gdb gdb.o cuda-api.o cuda-autostep.o cuda-asm.o cuda-commands.o cuda-context.o cuda-coords.o cuda-elf-image.o cuda-events.o cuda-exceptions.o cuda-frame.o cuda-gdb.o cuda-iterator.o cuda-kernel.o cuda-linux-nat.o cuda-modules.o cuda-convvars.o cuda-corelow.o cuda-notifications.o cuda-options.o cuda-packet-manager.o cuda-regmap.o cuda-special-register.o cuda-state.o cuda-tdep.o cuda-textures.o cuda-utils.o cuda-darwin-nat.o libcudbg.o libcudbgipc.o remote-cuda.o amd64-tdep.o amd64-linux-tdep.o i386-tdep.o i387-tdep.o i386-linux-tdep.o glibc-tdep.o solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o ser-base.o ser-unix.o ser-pipe.o ser-tcp.o inf-ptrace.o fork-child.o i386-nat.o amd64-nat.o amd64-linux-nat.o linux-nat.o linux-osdata.o proc-service.o linux-thread-db.o linux-fork.o linux-procfs.o linux-ptrace.o linux-btrace.o remote.o dcache.o tracepoint.o ax-general.o ax-gdb.o remote-fileio.o remote-notif.o  cli-dump.o cli-decode.o cli-script.o cli-cmds.o cli-setshow.o cli-logging.o cli-interp.o cli-utils.o mi-out.o mi-console.o mi-cmds.o mi-cmd-catch.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o mi-cmd-info.o mi-cuda.o mi-interp.o mi-main.o mi-parse.o mi-getopt.o tui-command.o tui-data.o tui-disasm.o tui-file.o tui-hooks.o tui-interp.o tui-io.o tui-layout.o tui-out.o tui-regs.o tui-source.o tui-stack.o tui-win.o tui-windata.o tui-wingeneral.o tui-winsource.o tui.o python.o py-arch.o py-auto-load.o py-block.o py-bpevent.o py-breakpoint.o py-cmd.o py-continueevent.o py-event.o py-evtregistry.o py-evts.o py-exitedevent.o py-finishbreakpoint.o py-frame.o py-function.o py-gdb-readline.o py-inferior.o py-infthread.o py-lazy-string.o py-newobjfileevent.o py-objfile.o py-param.o py-prettyprint.o py-progspace.o py-signalevent.o py-stopevent.o py-symbol.o py-symtab.o py-threadevent.o py-type.o py-utils.o py-value.o python-dynobj.o elfread.o stap-probe.o posix-hdep.o c-exp.o cp-name-parser.o ada-exp.o jv-exp.o f-exp.o go-exp.o m2-exp.o p-exp.o version.o annotate.o addrmap.o auto-load.o auxv.o agent.o bfd-target.o blockframe.o breakpoint.o break-catch-sig.o findvar.o regcache.o cleanups.o charset.o continuations.o corelow.o disasm.o dummy-frame.o dfp.o source.o value.o eval.o valops.o valarith.o valprint.o printcmd.o block.o symtab.o psymtab.o symfile.o symmisc.o linespec.o dictionary.o infcall.o infcmd.o infrun.o expprint.o environ.o stack.o thread.o exceptions.o filesystem.o f-module.o inf-child.o interps.o minidebug.o main.o macrotab.o macrocmd.o macroexp.o macroscope.o mi-common.o event-loop.o event-top.o inf-loop.o completer.o gdbarch.o arch-utils.o gdbtypes.o gdb_bfd.o gdb_obstack.o osabi.o copying.o memattr.o mem-break.o target.o parse.o language.o buildsym.o findcmd.o std-regs.o signals.o exec.o reverse.o bcache.o objfiles.o observer.o minsyms.o maint.o demangle.o dbxread.o coffread.o coff-pe-read.o dwarf2read.o mipsread.o stabsread.o corefile.o dwarf2expr.o dwarf2loc.o dwarf2-frame.o dwarf2-frame-tailcall.o ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o ada-tasks.o ada-varobj.o ui-out.o cli-out.o varobj.o vec.o go-lang.o go-valprint.o go-typeprint.o jv-lang.o jv-valprint.o jv-typeprint.o m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o sentinel-frame.o complaints.o typeprint.o ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o ada-valprint.o c-valprint.o cp-valprint.o d-valprint.o f-valprint.o m2-valprint.o serial.o mdebugread.o top.o utils.o ui-file.o user-regs.o frame.o frame-unwind.o doublest.o frame-base.o inline-frame.o gnu-v2-abi.o gnu-v3-abi.o cp-abi.o cp-support.o cp-namespace.o reggroups.o regset.o trad-frame.o tramp-frame.o solib.o solib-target.o prologue-value.o memory-map.o memrange.o xml-support.o xml-syscall.o xml-utils.o target-descriptions.o target-memory.o xml-tdesc.o xml-builtin.o inferior.o osdata.o gdb_usleep.o record.o record-full.o gcore.o gdb_vecs.o jit.o progspace.o skip.o probe.o common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o format.o registry.o btrace.o record-btrace.o cuda-parser.lex.o cuda-parser.tab.o inflow.o    init.o \
           ../readline/libreadline.a ../opcodes/libopcodes.a ../bfd/libbfd.a  ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    -ldl -lncurses -lz -lm -lexpat -llzma ../libiberty/libiberty.a  build-gnulib/import/libgnu.a ../libcudacore/libcudacore.a -ldl -Wl,--dynamic-list=../../gdb/proc-service.list
libcudbgipc.o: In function `cudbgipcPush':
libcudbgipc.c:(.text+0xb84): undefined reference to `pthread_kill'
libcudbgipc.o: In function `cudbgipcRead':
libcudbgipc.c:(.text+0xd21): undefined reference to `pthread_kill'
libcudbgipc.o: In function `cudbgipcWait':
libcudbgipc.c:(.text+0x1052): undefined reference to `pthread_kill'
libcudbgipc.o: In function `cudbgipcInitialize':
libcudbgipc.c:(.text+0x1425): undefined reference to `pthread_create'
libcudbgipc.o: In function `cudbgipcFinalize':
libcudbgipc.c:(.text+0x146f): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[2]: *** [gdb] Error 1
make[2]: Leaving directory `/home/marcusmae/apc/cuda-gdb/build/gdb'
make[1]: *** [all-gdb] Error 2
make[1]: Leaving directory `/home/marcusmae/apc/cuda-gdb/build'
make: *** [all] Error 2

The reason is -lpthread must apper after object files and static libraries, i.e. in the end of the command line, rather than in the beginning.

dmikushin commented 7 years ago

What works is:

./configure --program-prefix=cuda- --enable-cuda --enable-targets=x86_64-unknown-linux-gnu,m68k-unknown-linux-gnu CFLAGS='-I/opt/cuda/include' LIBS='-lpthread' LDFLAGS='-lpthread'

I.e. both LIBS and LDFLAGS.

And:

LOADLIBES = -ldl $(RDYNAMIC) -lpthread

in gdb/config/i386/linux64.mh

dmikushin commented 1 year ago

Thank you :+1: