<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello LLVM community,<br>
<br>
I am evaluating profitability of using the LLVM lld for linking our
projects.<br>
<br>
As a test, I tried to build the latest Boost with clang / lld on
X86_64 Ubuntu and faced a problem at the very first step of doing
this. One of the Boost's auxiliary tools refers to the "environ"
variable to access the environment variables. "environ" is defined
in glibc and is actually a weak alias for the "__environ" variable.
Here is a fragment of posix/environ.c:<br>
<font face="Arial"><br>
</font>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div class="pre" style="font-size: small; white-space: pre;
font-style: normal; font-variant: normal; font-weight: normal;
letter-spacing: normal; line-height: normal; text-align: start;
text-indent: 0px; text-transform: none; word-spacing: 0px;
background-color: rgb(255, 255, 255);"><big><font face="Arial">char **__environ = NULL;
// var pointing to env vars array</font></big></div>
<div class="pre" style="font-size: small; white-space: pre;
font-style: normal; font-variant: normal; font-weight: normal;
letter-spacing: normal; line-height: normal; text-align: start;
text-indent: 0px; text-transform: none; word-spacing: 0px;
background-color: rgb(255, 255, 255);"><big><font face="Arial">weak_alias (__environ, environ)
// and two weak aliases to it</font></big></div>
<font face="Arial">weak_alias (__environ, _environ)<br>
<br>
When linking a program that accesses "environ" with binutils' ld,
the symbol is correctly marked as a weak object:<br>
> </font>nm a.out | grep environ<br>
0000000000601040 B __environ@@GLIBC_2.2.5<br>
0000000000601040 <b>V </b><a class="moz-txt-link-abbreviated" href="mailto:environ@@GLIBC_2.2.5">environ@@GLIBC_2.2.5</a><br>
<br>
LLVM lld marks it as uninitialized data from the BSS section:<br>
0000000000401168 <b>B</b> environ<br>
<br>
Readelf also shows different symbols (readelf -s a.out | grep
environ):<br>
- ld:<br>
4: 0000000000601040 8 OBJECT WEAK DEFAULT 25
_environ@GLIBC_2.2.5 (2)<br>
5: 0000000000601040 8 OBJECT WEAK DEFAULT 25
<a class="moz-txt-link-abbreviated" href="mailto:environ@GLIBC_2.2.5">environ@GLIBC_2.2.5</a> (2) <- environ is a weak object<br>
6: 0000000000601040 8 OBJECT GLOBAL DEFAULT 25
__environ@GLIBC_2.2.5 (2) <- __environ itself is present as a
global<br>
54: 0000000000601040 8 OBJECT WEAK DEFAULT 25
<a class="moz-txt-link-abbreviated" href="mailto:environ@@GLIBC_2.2.5">environ@@GLIBC_2.2.5</a><br>
63: 0000000000601040 8 OBJECT GLOBAL DEFAULT 25
__environ@@GLIBC_2.2.5<br>
<br>
- lld<br>
1: 0000000000401168 8 OBJECT GLOBAL DEFAULT 22
environ <- no __environ reference. Environ is a global, not
weak<br>
8: 0000000000000000 8 OBJECT GLOBAL DEFAULT UND
environ<br>
37: 0000000000401168 8 OBJECT GLOBAL DEFAULT 22
environ<br>
<br>
This leads to "environ" being nil when running the lld-linked
binary.<br>
<br>
Is it a known problem?<br>
What is the fullness of ELF/Linux support?<br>
Where can I find the features list that are expected to work and
what work is still in progress?<br>
<br>
Thank you!<br>
<br>
Kind regards,<br>
Oleg<br>
</body>
</html>