1

I'm linking an application consisting out of two libraries in clang under WSL. The command I use looks as follows (simplified):

clang -m32 -fsanitize=address -L _build/ -l:lib1.lib -l:lib2.lib -o test
$ uname -a
Linux ******* 4.4.0-19041-Microsoft #1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux

clang is configured to use LD and the linking process finishes without issues. But when I try to run the file, I get

bash: ./test: cannot execute binary file: Exec format error

I have installed the libc6-i386:

$ sudo apt install libc6-i386
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6-i386 is already the newest version (2.31-0ubuntu9.7).
0 upgraded, 0 newly installed, 0 to remove and 70 not upgraded.
$ file ./test
./test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=dfdda2604f517942b1904bb686aa07b09f7ad968, for GNU/Linux 3.2.0, with debug_info, not stripped

$ objdump -p ./test

./test:     file format elf32-i386

Program Header:
    PHDR off    0x00000034 vaddr 0x08048034 paddr 0x08048034 align 2**2
         filesz 0x00000180 memsz 0x00000180 flags r--
  INTERP off    0x000001b4 vaddr 0x080481b4 paddr 0x080481b4 align 2**0
         filesz 0x00000013 memsz 0x00000013 flags r--
    LOAD off    0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12
         filesz 0x00026d60 memsz 0x00026d60 flags r--
    LOAD off    0x00027000 vaddr 0x0806f000 paddr 0x0806f000 align 2**12
         filesz 0x00217414 memsz 0x00217414 flags r-x
    LOAD off    0x0023f000 vaddr 0x08287000 paddr 0x08287000 align 2**12
         filesz 0x000c538c memsz 0x000c538c flags r--
    LOAD off    0x00305104 vaddr 0x0834e104 paddr 0x0834e104 align 2**12
         filesz 0x000230bc memsz 0x004879dc flags rw-
 DYNAMIC off    0x003058b8 vaddr 0x0834e8b8 paddr 0x0834e8b8 align 2**2
         filesz 0x00000128 memsz 0x00000128 flags rw-
    NOTE off    0x000001c8 vaddr 0x080481c8 paddr 0x080481c8 align 2**2
         filesz 0x00000044 memsz 0x00000044 flags r--
     TLS off    0x00305104 vaddr 0x0834e104 paddr 0x0834e104 align 2**2
         filesz 0x00000000 memsz 0x00000040 flags r--
EH_FRAME off    0x002be780 vaddr 0x08306780 paddr 0x08306780 align 2**2
         filesz 0x0000821c memsz 0x0000821c flags r--
   STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**4
         filesz 0x00000000 memsz 0x00000000 flags rw-
   RELRO off    0x00305104 vaddr 0x0834e104 paddr 0x0834e104 align 2**0
         filesz 0x00001efc memsz 0x00001efc flags r--

Dynamic Section:
  NEEDED               libpthread.so.0
  NEEDED               librt.so.1
  NEEDED               libm.so.6
  NEEDED               libdl.so.2
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6
  NEEDED               ld-linux.so.2
  INIT                 0x0806f000
  FINI                 0x082863fc
  PREINIT_ARRAY        0x0834e104
  PREINIT_ARRAYSZ      0x00000004
  INIT_ARRAY           0x0834e108
  INIT_ARRAYSZ         0x000002a0
  FINI_ARRAY           0x0834e3a8
  FINI_ARRAYSZ         0x000001cc
  GNU_HASH             0x0804820c
  STRTAB               0x08059644
  SYMTAB               0x0804d8b4
  STRSZ                0x000120d2
  SYMENT               0x00000010
  DEBUG                0x00000000
  PLTGOT               0x08350000
  PLTRELSZ             0x00000138
  PLTREL               0x00000011
  JMPREL               0x0806ec28
  REL                  0x0806d038
  RELSZ                0x00001bf0
  RELENT               0x00000008
  VERNEED              0x0806cec8
  VERNEEDNUM           0x00000006
  VERSYM               0x0806b716

Version References:
  required from libgcc_s.so.1:
    0x0b792653 0x00 14 GCC_3.3
    0x0b792650 0x00 13 GCC_3.0
  required from ld-linux.so.2:
    0x0d696913 0x00 10 GLIBC_2.3
    0x0d696911 0x00 08 GLIBC_2.1
  required from libm.so.6:
    0x0d696910 0x00 16 GLIBC_2.0
    0x06969183 0x00 07 GLIBC_2.23
  required from libdl.so.2:
    0x0d696910 0x00 09 GLIBC_2.0
    0x0d696911 0x00 05 GLIBC_2.1
  required from libpthread.so.0:
    0x09691a73 0x00 15 GLIBC_2.2.3
    0x0d696911 0x00 06 GLIBC_2.1
    0x0d696910 0x00 03 GLIBC_2.0
  required from libc.so.6:
    0x09691a74 0x00 18 GLIBC_2.2.4
    0x0d696916 0x00 17 GLIBC_2.6
    0x0d696911 0x00 12 GLIBC_2.1
    0x0d696912 0x00 11 GLIBC_2.2
    0x06969196 0x00 04 GLIBC_2.16
    0x0d696910 0x00 02 GLIBC_2.0

I have also tried to link with GCC front-end, but without luck.

Building/Linking without -m32 works, but I need -m32.

I'm running out of ideas, anyone a hint where to look at?

2

1 Answer 1

1

Solved.

Problem was that I was still on WSL1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .