[llvm-bugs] [Bug 48165] New: clang -pg produces invalid binaries on FreeBSD

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 12 15:35:10 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48165

            Bug ID: 48165
           Summary: clang -pg produces invalid binaries on FreeBSD
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: oleg-derevenetz at yandex.ru
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the following program:

$ cat test.c
#include <stdio.h>

int main()
{
    printf("OK\n");
}

When built using the following command:

$ clang -pg test.c

the following binary is produced:

$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically
linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.2, FreeBSD-style, with
debug_info, not stripped

(note the "interpreter /libexec/ld-elf.so.1" part).

Once launched, it crashes inside ld-elf.so.1 with SIGSEGV:

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/usr/home/oleg/tmp/pg/a.out' (x86_64).
(lldb) run
Process 872 launching
Process 872 launched: '/usr/home/oleg/tmp/pg/a.out' (x86_64)
Process 872 stopped
* thread #1, name = 'a.out', stop reason = signal SIGSEGV: invalid address
(fault address: 0x0)
    frame #0: 0x00000008002a3ab0
->  0x8002a3ab0: movq   (%r15), %rdx
    0x8002a3ab3: cmpq   $0x6fffffef, %rdx         ; imm = 0x6FFFFFEF
    0x8002a3aba: jg     0x8002a3b10
    0x8002a3abc: cmpq   $0x21, %rdx
(lldb) disassemble
->  0x8002a3ab0: movq   (%r15), %rdx
    0x8002a3ab3: cmpq   $0x6fffffef, %rdx         ; imm = 0x6FFFFFEF
    0x8002a3aba: jg     0x8002a3b10
    0x8002a3abc: cmpq   $0x21, %rdx
    0x8002a3ac0: ja     0x8002a3ba6
    0x8002a3ac6: movslq (%r12,%rdx,4), %rax
    0x8002a3aca: addq   %r12, %rax
    0x8002a3acd: jmpq   *%rax
(lldb)

Disassembled code above is apparently from ld-elf.so.1/_rtld_is_dlopened.

However, if the following command is used for the build:

$ clang -pg -static test.c

the following binary is produced:

$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically
linked, for FreeBSD 12.2, FreeBSD-style, with debug_info, not stripped

(note the absence of "interpreter ..." part). This binary runs just fine:

$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/usr/home/oleg/tmp/pg/a.out' (x86_64).
(lldb) run
Process 914 launching
Process 914 launched: '/usr/home/oleg/tmp/pg/a.out' (x86_64)
OK
Process 914 exited with status = 0 (0x00000000)
(lldb)

$ clang --version
FreeBSD clang version 10.0.1 (git at github.com:llvm/llvm-project.git
llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd12.2
Thread model: posix
InstalledDir: /usr/bin

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201112/5275a1e6/attachment.html>


More information about the llvm-bugs mailing list