0

I'm trying to translate linux x86 assembler to llvm assembler.

Actually, I don't get any assembler, Is it possible to translate or decompile GNU assembler to llvm assembler?

If any, what is the tool?

or need to decompile and assemble with clang?

----------- os_Linux_x86.s in NSPR :

// -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// 
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val)
//
// Atomically increment the integer pointed to by 'val' and return
// the result of the increment.
//
    .text
    .globl _PR_x86_AtomicIncrement
    .align 4
_PR_x86_AtomicIncrement:
    movl 4(%esp), %ecx
    movl $1, %eax
    lock
    xaddl %eax, (%ecx)
    incl %eax
    ret

......
Marco Jo
  • 33
  • 3
  • What exactly is LLVM assembler? – fuz Dec 27 '18 at 12:27
  • I mean the code LLVM can understand. Actually, i need a LLVM-IR code – Marco Jo Dec 28 '18 at 01:32
  • I don't think what you want is actually possible. – fuz Dec 28 '18 at 08:41
  • Are you sure you need to decompile to LLVM-IR? LLVM for x86 should be able to assemble this. e.g. `clang -m32 -c`. But really, if you have functions like this, you should use GNU C `__atomic_fetch_add()` or ISO C11 stdatomic, or ISO C++11 std::atomic, so the compiler can optimize to a simple `lock add` if the old value isn't needed, and remove the overhead of a function call. (spilling registers and so on). – Peter Cordes Dec 30 '18 at 05:31
  • 1
    @MarcoJo what you are looking for is called 'lifting'. You can find several threads and tools on internet. Try to search for "llvm assembly lifting", that should give you the right direction. – AlexDenisov Dec 31 '18 at 11:16

0 Answers0