This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: configure munges $ORIGIN in LDFLAGS (SOLVED)


>  From: Poor Yorick <org.sourceware.binutils@pooryorick.com>
>  Subject: configure munges $ORIGIN in LDFLAGS
>  
>  Using a shell script to build binutils-2.19.1, LDFLAGS assignment looks like this:
>  
>          -Wl,-rpath,/path/to/bootstrap/lib -Wl,-rpath,/path/to/bootstrap/lib64
>          -Wl,-rpath,'$$ORIGIN/../lib' -Wl,-rpath,'$$ORIGIN/../lib64'
>          -Wl,-rpath,'$$ORIGIN/../../lib' -Wl,-rpath,'$$ORIGIN/../../lib64'
>          -Wl,-rpath,/path/to/bootstrap/glibc/lib64
>          -Wl,-rpath,/path/to/bootstrap/glibc/lib -L/path/to/lib -L/path/to/lib64
>          -L/path/to/bootstrap/glibc/lib
>          -Wl,--dynamic-linker,/path/to/bootstrap/glibc/lib/ld-linux-x86-64.so.2
>          -Wl,-z,origin -Wl,--enable-new-dtags
>  
>  in the main Makefile, LDFLAGS and LDFLAGS_FOR_BUILD are as expected:
>  
>          -Wl,-rpath,/path/to/bootstrap/lib -Wl,-rpath,/path/to/bootstrap/lib64
>          -Wl,-rpath,'$$ORIGIN/../lib' -Wl,-rpath,'$$ORIGIN/../lib64'
>          -Wl,-rpath,'$$ORIGIN/../../lib' -Wl,-rpath,'$$ORIGIN/../../lib64'
>          -Wl,-rpath,/path/to/bootstrap/glibc/lib64
>          -Wl,-rpath,/path/to/bootstrap/glibc/lib -L/path/to/lib -L/path/to/lib64
>          -L/path/to/bootstrap/glibc/lib
>          -Wl,--dynamic-linker,/path/to/bootstrap/glibc/lib/ld-linux-x86-64.so.2
>          -Wl,-z,origin -Wl,--enable-new-dtags
>  
>  However, in binutils/Makefile, $$ORIGIN gets swallowed:
>  
>          LDFLAGS = -Wl,-rpath,/path/to/bootstrap/lib
>          -Wl,-rpath,/path/to/bootstrap/lib64 -Wl,-rpath,'/../lib'
>          -Wl,-rpath,'/../lib64' -Wl,-rpath,'/../../lib'
>          -Wl,-rpath,'/../../lib64' -Wl,-rpath,/path/to/bootstrap/glibc/lib64
>          -Wl,-rpath,/path/to/bootstrap/glibc/lib -L/path/to/lib -L/path/to/lib64
>          -L/path/to/bootstrap/glibc/lib
>          -Wl,--dynamic-linker,/path/to/bootstrap/glibc/lib/ld-linux-x86-64.so.2
>          -Wl,-z,origin -Wl,--enable-new-dtags
>  
>  Causing the build to fail, since executables don't get the right paths.
>  Apparently, the top Makefile needs to requote arguments before invoking
>  binutils/configure.  Could someone more familiar with the scripts give me a
>  clue where to look to make this
>  happen?
>  

It turns out that, in one of the most heinous cases of escaping I have ever seen in production code, this is the correct way to quote $ORIGIN in the top-level Makefile:

        LDFLAGS = -Wl,-rpath,/path/to/bootstrap/lib
        -Wl,-rpath,/path/to/bootstrap/lib64
        -Wl,-rpath,'$\\$$\$$\\$$\$$ORIGIN/../lib'
        -Wl,-rpath,'$\\$$\$$\\$$\$$ORIGIN/../lib64'
        -Wl,-rpath,'$\\$$\$$\\$$\$$ORIGIN/../../lib'
        -Wl,-rpath,'$\\$$\$$\\$$\$$ORIGIN/../../lib64'
        -Wl,-rpath,/path/to/bootstrap/glibc/lib64
        -Wl,-rpath,/path/to/bootstrap/glibc/lib -L/path/to/lib -L/path/to/lib64
        -L/path/to/bootstrap/glibc/lib
        -Wl,--dynamic-linker,/path/to/bootstrap/glibc/lib/ld-linux-x86-64.so.2
        -Wl,-z,origin -Wl,--enable-new-dtags

In the script that sets LDFLAGS before calling Makefile, LDFLAGS can therefore
be massages like so to get the correct result:

        LDFLAGS="${LDFLAGS//\$ORIGIN/\\\\\$$\\\$$\\\\\$$\\\$\$ORIGIN}"

If that isn't evil, I don't know what is.  I shudder to think of the syntax
that would have been involved had secondary expansion been enabled in Makefile.
Perhaps it is time to convert the entire GNU build system to Python!

-- 
Yorick



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]