This is an archive of the discontinued LLVM Phabricator instance.

Fix for aarch64 lldb-server native builds
AbandonedPublic

Authored by omjavaid on Mar 19 2015, 10:07 AM.

Details

Summary

This patch fixes a glitch in cmake scripts which was routing to a wrong python library directory when building lldb-server on aarch64 natively.

I have skipped the hardcoded values once user provides a value for CMAKE_LIBRARY_ARCHITECTURE during configure.

Diff Detail

Event Timeline

omjavaid updated this revision to Diff 22267.Mar 19 2015, 10:07 AM
omjavaid retitled this revision from to Fix for aarch64 lldb-server native builds.
omjavaid updated this object.
omjavaid edited the test plan for this revision. (Show Details)
omjavaid added reviewers: zturner, vharron.
omjavaid added a subscriber: Unknown Object (MLST).
zturner added inline comments.Mar 19 2015, 10:13 AM
cmake/modules/LLDBConfig.cmake
44–49

Should this be independently of whether LLDB_DISABLE_PYTHON is set, I wonder? I know the issue only seems to be surfacing for you when linking against python. But the CMAKE_LIBRARY_ARCHITECTURE variable is unrelated to linking Python. On that note, is this something that should be in LLVM's base CMake?

Hi Omair,

While it's good to move away from wrong hard-coded values, but we should make it more generic. If you're building all together, there's a CMake function called get_host_triple() at LLVM's cmake/modules/GetHostTriple.cmake that you could use, or just use LLVM_HOST_TRIPLE.

If that's wrong, than I think Zach is right that this may have to be fixed on the LLVM side.

cmake/modules/LLDBConfig.cmake
44–49

On that note, is this something that should be in LLVM's base CMake?

I think so. "arm-linux-gnueabi" is definitely not enough for ARM. We may need to re-use what LLVM's base does and set this with that value.

You can specify LLVM_HOST_TRIPLE from the command line (e.g.: -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-android) and it have to be specified correctly because it used in some place in lldb-server. I think we should use that one instead of introducing a new variable.

Tamas:
There is no new variable being introduced and even if you supply
-DLLVM_HOST_TRIPLE from commandline this config file will still
encounter the bug.

Renato:
My knowledge of LLVM source is limited so I have tried to make the
hack that was already there in the LLDBConfig.cmake more usable. I ll
try if I can get the host triple using the function you have
mentioned.

Currently it looks something like this:

if (NOT LLDB_DISABLE_PYTHON)

if(UNIX)

> we are bound to come here on any UNIX/Linux system

  1. This is necessary for crosscompile on Ubuntu 14.04 64bit. Need a

proper fix.

if(CMAKE_SIZEOF_VOID_P EQUAL 8)

> And here we are forcing the triple to x86_64-linux-gnu in case we

encounter a 64bit target which is wrong.

    set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
  endif()
endif()
if (MSVC)
  if ("${PYTHON_INCLUDE_DIR}" STREQUAL "" OR "${PYTHON_LIBRARY}" STREQUAL "")
    message("-- LLDB Embedded python disabled.  Embedding python on

Windows requires "

            "manually specifying PYTHON_INCLUDE_DIR *and* PYTHON_LIBRARY")
    set(LLDB_DISABLE_PYTHON 1)
  else()
    message("-- Found PythonLibs: ${PYTHON_LIBRARY}")
    include_directories(${PYTHON_INCLUDE_DIR})
  endif()
else()
  find_package(PythonLibs REQUIRED)
  include_directories(${PYTHON_INCLUDE_DIRS})
endif()

endif()

Tamas:
There is no new variable being introduced and even if you supply
-DLLVM_HOST_TRIPLE from commandline this config file will still
encounter the bug.

This probably means that the LLDB CMake file is not well integrated. I don't know how much LLDB needs to be compiled inside LLVM, but that seems to be the standard for everything else. Does anyone know how to use the CMake modules on other projects?

> And here we are forcing the triple to x86_64-linux-gnu in case we

encounter a 64bit target which is wrong.

Yes, this is completely wrong. But instead of guessing, we should be using what LLVM does. AFAIK, LLVM uses that GetHostTriple module to guess the triple, and later on, it uses that if the user hasn't specified in the command line. We should do the exact same thing on all projects, including LLDB.

But unfortunately, like you, I know very little of CMake and how it's used in other projects... :(

I'm hoping someone around could give us a hand.

cheers,
--renato

I still think this needs to be fixed in LLVM and not in LLDB. CMAKE_LIBRARY_ARCHITECTURE is a variable that any library, not just LLDB, might want to check. And if it's not correct in LLDB, then it's not going to be correct anywhere else either.

I've added chandlerc. I know a little about LLVM's CMake, but not as much as Chandler, so maybe he could give us a hand and see if he agrees that this belongs in LLVM CMake.

I still think this needs to be fixed in LLVM and not in LLDB. CMAKE_LIBRARY_ARCHITECTURE is a variable that any library, not just LLDB, might want to check. And if it's not correct in LLDB, then it's not going to be correct anywhere else either.

I can't find CMAKE_LIBRARY_ARCHITECTURE anywhere else in the LLVM projects... But since this is a CMAKE variable, not an LLVM one, we may need to set it with the host triple, so that it's correct for all projects that might need it in the future.

Omair,

What about setting that variable with the result of LLVM_HOST_TRIPLE set at LLVM src/cmake/config-ix.cmake line 324? Maybe adding a line right after it to set should do the trick.
cheers,
--renato

omjavaid updated this revision to Diff 23671.Apr 13 2015, 4:30 AM
omjavaid edited edge metadata.

As it turns out that this issue only occurs on 64bit host architecture so I am adding this trivial solution with attached updated patch.

Hi Omair,

It looks good to me, but wait for Zachary's comment before committing.

cheers,
--renato

cmake/modules/LLDBConfig.cmake
40

This is not a proper fix for target identification, but it does solve the more pressing problem of getting a hard-coded triple.

chandlerc requested changes to this revision.May 27 2015, 2:16 AM
chandlerc edited edge metadata.

Closing the loop here: this is not the correct patch. Zach is completely correct here.

If some core part of LLVM (and thus LLDB) is getting the CMAKE_LIBRARY_ARCHITECTURE wrong, we need to go fix *that*. It isn't at all clear why it would be wrong, but this patch is not the correct fix.

This revision now requires changes to proceed.May 27 2015, 2:16 AM
omjavaid abandoned this revision.Feb 9 2016, 1:09 AM