Understanding the version handling in LLVM/Clang/LLD

[ Please CC me I ma not subcribed to this mailing-list ]

[ CC Tom and Hans as LLVM/stable maintainers ]

Hi,

I want to understand the version handling in LLVM/Clang/LLD.

Normally, I build from "release/10.x" Git branch by using the tool
tc-build from ClangBuiltLinux project.

With "llvm-10.0.1-rc1" Git tag I was able to setup a llvm-toolchain
consisting of the projects "clang" and "lld".

A Linux v5.7-rc6 was successfully built.

$ cat /proc/version
Linux version 5.7.0-rc6-2-amd64-clang (sedat.dilek@gmail.com@iniza)
(ClangBuiltLinux clang version 10.0.1
(https://github.com/llvm/llvm-project
f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6), LLD 10.0.1
(https://github.com/llvm/llvm-project
f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6)) #2~bullseye+dileks1 SMP
2020-05-20

I remember when I used official tarballs for RC releases, the version
string should look like:

$ clang-10 --version
dileks clang version 10.0.1rc1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dileks/src/llvm-toolchain/install/bin

$ ld.lld --version
LLD 10.0.1rc1 (compatible with GNU linkers)

$ llvm-as --version
LLVM (http://llvm.org/):
  LLVM version 10.0.1rc1
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: sandybridge

My first change:

[ llvm/CMakeLists.txt ]

if(NOT DEFINED LLVM_VERSION_SUFFIX)
- set(LLVM_VERSION_SUFFIX "")
+ set(LLVM_VERSION_SUFFIX "rc1")
endif()

Unfortunately, clang-10 and ld.lld binaries did not show this in their version.

So, I modified clang...

[ clang/CMakeLists.txt ]

-# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
-set(CLANG_VERSION
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
+if(NOT DEFINED CLANG_VERSION_SUFFIX)
+ set(CLANG_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
+endif()
+# CLANG_VERSION includes LLVM_VERSION_SUFFIX.
+set(CLANG_VERSION
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}${CLANG_VERSION_SUFFIX}")

...and lld (the same way clang handles its version):

[ lld/CMakeLists.txt ]

-# Compute the LLD version from the LLVM version.
-string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
- ${PACKAGE_VERSION})
+# If LLD_VERSION_* is specified, use it, if not use LLVM_VERSION_*.
+if(NOT DEFINED LLD_VERSION_MAJOR)
+ set(LLD_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
+endif()
+if(NOT DEFINED LLD_VERSION_MINOR)
+ set(LLD_VERSION_MINOR ${LLVM_VERSION_MINOR})
+endif()
+if(NOT DEFINED LLD_VERSION_PATCHLEVEL)
+ set(LLD_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
+endif()
+if(NOT DEFINED LLD_VERSION_SUFFIX)
+ set(LLD_VERSION_SUFFIX ${LLVM_VERSION_SUFFIX})
+endif()
+# LLD_VERSION includes LLVM_VERSION_SUFFIX.
+set(LLD_VERSION
"${LLD_VERSION_MAJOR}.${LLD_VERSION_MINOR}.${LLD_VERSION_PATCHLEVEL}${LLD_VERSION_SUFFIX}")
message(STATUS "LLD version: ${LLD_VERSION}")

-string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
- ${LLD_VERSION})
-string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
- ${LLD_VERSION})

Forgot the patch.

- Sedat -

LLVM_VERSION_SUFFIX-v4.diff (5.54 KB)

[ Please CC me I ma not subcribed to this mailing-list ]

[ CC Tom and Hans as LLVM/stable maintainers ]

Hi,

I want to understand the version handling in LLVM/Clang/LLD.

Normally, I build from "release/10.x" Git branch by using the tool
tc-build from ClangBuiltLinux project.

With "llvm-10.0.1-rc1" Git tag I was able to setup a llvm-toolchain
consisting of the projects "clang" and "lld".

A Linux v5.7-rc6 was successfully built.

$ cat /proc/version
Linux version 5.7.0-rc6-2-amd64-clang (sedat.dilek@gmail.com@iniza)
(ClangBuiltLinux clang version 10.0.1
(https://github.com/llvm/llvm-project
f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6), LLD 10.0.1
(https://github.com/llvm/llvm-project
f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6)) #2~bullseye+dileks1 SMP
2020-05-20

I remember when I used official tarballs for RC releases, the version
string should look like:

$ clang-10 --version
dileks clang version 10.0.1rc1

Are you sure about this? I don't remember rc# being added to version
strings, do you have an example of an older release build that does this?

-Tom

> [ Please CC me I ma not subcribed to this mailing-list ]
>
> [ CC Tom and Hans as LLVM/stable maintainers ]
>
> Hi,
>
> I want to understand the version handling in LLVM/Clang/LLD.
>
> Normally, I build from "release/10.x" Git branch by using the tool
> tc-build from ClangBuiltLinux project.
>
> With "llvm-10.0.1-rc1" Git tag I was able to setup a llvm-toolchain
> consisting of the projects "clang" and "lld".
>
> A Linux v5.7-rc6 was successfully built.
>
> $ cat /proc/version
> Linux version 5.7.0-rc6-2-amd64-clang (sedat.dilek@gmail.com@iniza)
> (ClangBuiltLinux clang version 10.0.1
> (https://github.com/llvm/llvm-project
> f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6), LLD 10.0.1
> (https://github.com/llvm/llvm-project
> f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6)) #2~bullseye+dileks1 SMP
> 2020-05-20
>
> I remember when I used official tarballs for RC releases, the version
> string should look like:
>
> $ clang-10 --version
> dileks clang version 10.0.1rc1

Are you sure about this? I don't remember rc# being added to version
strings, do you have an example of an older release build that does this?

Hi Tom,

yesterday morning I downloaded llvm-5.0.0rc5.src.tar.xz to check
myself before you answered me:

[ llvm-5.0.0rc5.src/CMakeLists.txt ]

if(NOT DEFINED LLVM_VERSION_MAJOR)
  set(LLVM_VERSION_MAJOR 5)
endif()
if(NOT DEFINED LLVM_VERSION_MINOR)
  set(LLVM_VERSION_MINOR 0)
endif()
if(NOT DEFINED LLVM_VERSION_PATCH)
  set(LLVM_VERSION_PATCH 0)
endif()
if(NOT DEFINED LLVM_VERSION_SUFFIX)
  set(LLVM_VERSION_SUFFIX "")
endif()

"I am a bad liar..." (see [1]) or digital dementia :-)?

I have to check my old build-script from my archived Ubuntu/precise
12.04 LTS system.
Darkly I remember I played with some "program-suffix" options.
I will report later.

I will also double check some older binaries from
<https://snapshot.debian.org/&gt; to see if I recall correct and decide
if I need a red or blue pill.

Thanks for taking care!

Regards,
- Sedat -

[1] Imagine Dragons - Bad Liar (Official Music Video) - YouTube
[2] llvm-toolchain-3.6 - snapshot.debian.org

I will also double check some older binaries from
<https://snapshot.debian.org/&gt; to see if I recall correct and decide
if I need a red or blue pill.

OK, I have installed clang-7 version 1:7.0.1~+rc3-1 from
snapshot.debian.org (see instructions below).

In times of SVN we had a tags/RELEASE_XXX/rcY:

# LC_ALL=C clang-7 -v
clang version 7.0.1-+rc3-1 (tags/RELEASE_701/rc3)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

Maybe I mixed that up.

Is that different with switching to Git?

- Sedat -

P.S.: Instructions

LINK: linux - Install packages from the Debian Snapshot Archives repo? - Stack Overflow
LINK: https://snapshot.debian.org/package/llvm-toolchain-7/1%3A7.0.1~%2Brc3-2/

# cat /etc/apt/sources.list.d/debian-snapshot.list
deb http://snapshot.debian.org/archive/debian/20181214 unstable main

# cat /etc/apt/preferences.d/990_debian-snapshot
Package: *
Pin: origin "snapshot.debian.org"
Pin-Priority: 990

# apt-get -o Acquire::Check-Valid-Until=false update

# apt-cache policy clang-7
clang-7:
  Installed: None
  Candidate: 1:7.0.1~+rc3-1
  Version table:
     1:7.0.1-12 99
         99 Index of /debian unstable/main amd64 Packages
         99 Index of /debian unstable/main amd64 Packages
     1:7.0.1-8 500
        500 Index of /debian buster/main amd64 Packages
        500 Index of /debian buster/main amd64 Packages
     1:7.0.1~+rc3-1 990
        990 http://snapshot.debian.org/archive/debian/20181214
unstable/main amd64 Packages

# apt-get install --no-install-recommends --allow-unauthenticated
clang-7=1:7.0.1~+rc3-1 libclang-common-7-dev=1:7.0.1~+rc3-1
libclang1-7=1:7.0.1~+rc3-1 libllvm7=1:7.0.1~+rc3-1 -t unstable -y

- EOT -

With my modifications I was able to build and boot a Linux v5.7-rc6+
kernel on Debian/testing AMD64.

root@iniza:~# cat /proc/version
Linux version 5.7.0-rc6-4-amd64-clang (sedat.dilek@gmail.com@iniza)
(clang version 10.0.1rc1, LLD 10.0.1rc1) #4~bullseye+dileks1 SMP
2020-05-22

- Sedat -

I have downloaded the llvm-toolchain from [1]:

dileks@iniza:~/src/llvm-toolchain/clang+llvm-10.0.1-rc1-x86_64-pc-linux-gnu/bin$
./clang-10 -v
clang version 10.0.1 (https://github.com/llvm/llvm-project.git
01636c1eeace5371fef8508c7318df9d7a25b489)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/dileks/src/llvm-toolchain/clang+llvm-10.0.1-rc1-x86_64-pc-linux-gnu/bin/.
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

dileks@iniza:~/src/llvm-toolchain/clang+llvm-10.0.1-rc1-x86_64-pc-linux-gnu/bin$
./ld.lld -v
LLD 10.0.1 (https://github.com/llvm/llvm-project.git
01636c1eeace5371fef8508c7318df9d7a25b489) (compatible with GNU
linkers)

What is that for a commit-hash-id?

Even on master Git branch:

$ git describe --contains 01636c1eeace5371fef8508c7318df9d7a25b489
fatal: cannot describe '01636c1eeace5371fef8508c7318df9d7a25b489'

$ git describe --contains f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6
llvmorg-10.0.1-rc1

Last commit in release/10.x before llvmorg-10.0.1-rc1 was tagged:
"[arm] Add big-endian version of pcrel fixups for adr instructions"

Commit-hash-id of the tag?

- Sedat -

[1] https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1-rc1/clang+llvm-10.0.1-rc1-x86_64-pc-linux-gnu.tar.xz
[2] https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1-rc1/clang+llvm-10.0.1-rc1-x86_64-pc-linux-gnu.tar.xz.sig
[3] [arm] Add big-endian version of pcrel fixups for adr instructions · llvm/llvm-project@f79cd71 · GitHub

Hmm,

$ git show-ref --tags | grep 10.0.1-rc1
f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6 refs/tags/llvmorg-10.0.1-rc1

$ ./clang-10 -v | grep Target
clang version 10.0.1 (https://github.com/llvm/llvm-project.git
01636c1eeace5371fef8508c7318df9d7a25b489)
Target: x86_64-unknown-linux-gnu

The tarball name says
clang+llvm-10.0.1-rc1-***x86_64-pc-linux-gnu***.tar.xz but it's
"Target: x86_64-unknown-linux-gnu".

- Sedat -