<div dir="ltr">I actually started doing this and noticed that it needs a change how we instantiate a file object. Let me finish that first.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 24, 2017 at 1:54 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am giving that a try.<br>
<br>
Cheers,<br>
Rafael<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 24 April 2017 at 16:35, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> On Mon, Apr 24, 2017 at 1:33 PM, Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>><br>
> wrote:<br>
>><br>
>><br>
>><br>
>> On Mon, Apr 24, 2017 at 1:28 PM, Rui Ueyama via llvm-commits<br>
>> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> On Mon, Apr 24, 2017 at 1:22 PM, Rafael Espíndola via llvm-commits<br>
>>> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>>><br>
>>>> On 11 April 2017 at 19:46, Evgeniy Stepanov via llvm-commits<br>
>>>> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>>> > Author: eugenis<br>
>>>> > Date: Tue Apr 11 18:46:58 2017<br>
>>>> > New Revision: 300007<br>
>>>> ><br>
>>>> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=300007&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=300007&view=rev</a><br>
>>>> > Log:<br>
>>>> > [lld] Keep full library path in DT_NEEDED.<br>
>>>> ><br>
>>>> > Fixes PR32572.<br>
>>>> ><br>
>>>> > When<br>
>>>> >     (a) a library has no soname<br>
>>>> > and (b) library is given on the command line with path (and not<br>
>>>> > through -L/-l flags)<br>
>>>> > DT_NEEDED entry for such library keeps the path as given.<br>
>>>> ><br>
>>>> > This behavior is consistent with gold and bfd, and is used in<br>
>>>> > compiler-rt test suite.<br>
>>>> ><br>
>>>> > Added:<br>
>>>> >     lld/trunk/test/ELF/no-soname.s<br>
>>>> > Modified:<br>
>>>> >     lld/trunk/ELF/Driver.cpp<br>
>>>> >     lld/trunk/ELF/Driver.h<br>
>>>> >     lld/trunk/ELF/InputFiles.cpp<br>
>>>> >     lld/trunk/ELF/InputFiles.h<br>
>>>> >     lld/trunk/ELF/ScriptParser.cpp<br>
>>>> >     lld/trunk/test/ELF/as-needed-<wbr>no-reloc.s<br>
>>>> >     lld/trunk/test/ELF/relro-<wbr>omagic.s<br>
>>>> ><br>
>>>> > Modified: lld/trunk/ELF/Driver.cpp<br>
>>>> > URL:<br>
>>>> > <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=300007&r1=300006&r2=300007&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Driver.<wbr>cpp?rev=300007&r1=300006&r2=<wbr>300007&view=diff</a><br>
>>>> ><br>
>>>> > ==============================<wbr>==============================<wbr>==================<br>
>>>> > --- lld/trunk/ELF/Driver.cpp (original)<br>
>>>> > +++ lld/trunk/ELF/Driver.cpp Tue Apr 11 18:46:58 2017<br>
>>>> > @@ -153,7 +153,7 @@ LinkerDriver::<wbr>getArchiveMembers(MemoryBu<br>
>>>> ><br>
>>>> >  // Opens and parses a file. Path has to be resolved already.<br>
>>>> >  // Newly created memory buffers are owned by this driver.<br>
>>>> > -void LinkerDriver::addFile(<wbr>StringRef Path) {<br>
>>>> > +void LinkerDriver::addFile(<wbr>StringRef Path, bool WithLOption) {<br>
>>>> >    using namespace sys::fs;<br>
>>>> ><br>
>>>> >    Optional<MemoryBufferRef> Buffer = readFile(Path);<br>
>>>> > @@ -184,6 +184,11 @@ void LinkerDriver::addFile(<wbr>StringRef Pat<br>
>>>> >        return;<br>
>>>> >      }<br>
>>>> >      Files.push_back(<wbr>createSharedFile(MBRef));<br>
>>>> > +    // If the library is found at an explicitly given path use the<br>
>>>> > entire path<br>
>>>> > +    // as he default soname. Such libraries should not require RPATH<br>
>>>> > or<br>
>>>> > +    // LD_LIBRARY_PATH to run.<br>
>>>> > +    Files.back()->DefaultSoName =<br>
>>>> > +        WithLOption ? sys::path::filename(Path) : Path;<br>
>>>> >      return;<br>
>>>> >    default:<br>
>>>> >      if (InLib)<br>
>>>> > @@ -196,7 +201,7 @@ void LinkerDriver::addFile(<wbr>StringRef Pat<br>
>>>> >  // Add a given library by searching it from input search paths.<br>
>>>> >  void LinkerDriver::addLibrary(<wbr>StringRef Name) {<br>
>>>> >    if (Optional<std::string> Path = searchLibrary(Name))<br>
>>>> > -    addFile(*Path);<br>
>>>> > +    addFile(*Path, /*WithLOption=*/true);<br>
>>>> >    else<br>
>>>> >      error("unable to find library -l" + Name);<br>
>>>> >  }<br>
>>>> > @@ -762,7 +767,7 @@ void LinkerDriver::createFiles(opt:<wbr>:Inpu<br>
>>>> >        addLibrary(Arg->getValue());<br>
>>>> >        break;<br>
>>>> >      case OPT_INPUT:<br>
>>>> > -      addFile(Arg->getValue());<br>
>>>> > +      addFile(Arg->getValue(), /*WithLOption=*/false);<br>
>>>> >        break;<br>
>>>> >      case OPT_alias_script_T:<br>
>>>> >      case OPT_script:<br>
>>>> ><br>
>>>> > Modified: lld/trunk/ELF/Driver.h<br>
>>>> > URL:<br>
>>>> > <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=300007&r1=300006&r2=300007&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Driver.<wbr>h?rev=300007&r1=300006&r2=<wbr>300007&view=diff</a><br>
>>>> ><br>
>>>> > ==============================<wbr>==============================<wbr>==================<br>
>>>> > --- lld/trunk/ELF/Driver.h (original)<br>
>>>> > +++ lld/trunk/ELF/Driver.h Tue Apr 11 18:46:58 2017<br>
>>>> > @@ -27,7 +27,7 @@ extern class LinkerDriver *Driver;<br>
>>>> >  class LinkerDriver {<br>
>>>> >  public:<br>
>>>> >    void main(ArrayRef<const char *> Args, bool CanExitEarly);<br>
>>>> > -  void addFile(StringRef Path);<br>
>>>> > +  void addFile(StringRef Path, bool WithLOption);<br>
>>>> >    void addLibrary(StringRef Name);<br>
>>>> ><br>
>>>> >  private:<br>
>>>> ><br>
>>>> > Modified: lld/trunk/ELF/InputFiles.cpp<br>
>>>> > URL:<br>
>>>> > <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=300007&r1=300006&r2=300007&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>InputFiles.cpp?rev=300007&r1=<wbr>300006&r2=300007&view=diff</a><br>
>>>> ><br>
>>>> > ==============================<wbr>==============================<wbr>==================<br>
>>>> > --- lld/trunk/ELF/InputFiles.cpp (original)<br>
>>>> > +++ lld/trunk/ELF/InputFiles.cpp Tue Apr 11 18:46:58 2017<br>
>>>> > @@ -661,7 +661,7 @@ template <class ELFT> void SharedFile<EL<br>
>>>> >    // DSOs are identified by soname, and they usually contain<br>
>>>> >    // DT_SONAME tag in their header. But if they are missing,<br>
>>>> >    // filenames are used as default sonames.<br>
>>>> > -  SoName = sys::path::filename(this-><wbr>getName());<br>
>>>> > +  SoName = this->DefaultSoName;<br>
>>>> ><br>
>>>> >    if (!DynamicSec)<br>
>>>> >      return;<br>
>>>> ><br>
>>>> > Modified: lld/trunk/ELF/InputFiles.h<br>
>>>> > URL:<br>
>>>> > <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=300007&r1=300006&r2=300007&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>InputFiles.h?rev=300007&r1=<wbr>300006&r2=300007&view=diff</a><br>
>>>> ><br>
>>>> > ==============================<wbr>==============================<wbr>==================<br>
>>>> > --- lld/trunk/ELF/InputFiles.h (original)<br>
>>>> > +++ lld/trunk/ELF/InputFiles.h Tue Apr 11 18:46:58 2017<br>
>>>> > @@ -93,6 +93,10 @@ public:<br>
>>>> >    uint16_t EMachine = llvm::ELF::EM_NONE;<br>
>>>> >    uint8_t OSABI = 0;<br>
>>>> ><br>
>>>> > +  // For SharedKind inputs, the string to use in DT_NEEDED when the<br>
>>>> > library<br>
>>>> > +  // has no soname.<br>
>>>> > +  std::string DefaultSoName;<br>
>>>><br>
>>>> Why do you need this to be in the base class?<br>
>>><br>
>>><br>
>>> I found this odd too, but it turned out that SharedFile is a template<br>
>>> class, and in this context we don't know about ELFT, so it's not easy to<br>
>>> cast a file object to SharedFile<ELFT> here.<br>
>><br>
>><br>
>> Though couldn't the default soname just be an argument to<br>
>> createSharedFile?<br>
><br>
><br>
> I don't know why I didn't notice, but it seems it can.<br>
</div></div></blockquote></div><br></div>