Issue #12276 has been updated by Nobuyoshi Nakada.

Status changed from Feedback to Closed

Quote by single quotes.

```
$ LDFLAGS=" -Wl,-rpath='\$\$ORIGIN/../lib' " ./configure
$ make

$ readelf -d ruby|grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib:/usr/local/lib]

$ readelf -d .ext/x86_64-linux/stringio.so|grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib]
```

----------------------------------------
Bug #12276: Quoting error involving '$' characters in DT_RPATH pathnames
https://bugs.ruby-lang.org/issues/12276#change-62524

* Author: Evan Miller
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Often it's desired to use DT_RPATH in Ruby and associated extension objects when bundling custom libraries for a Ruby application. Often absolute paths cannot be known at build-time, so the linker provides the $ORIGIN macro used to build paths relative to the object being linked (This is a platform-specific linker feature, though fairly commonly implemented. Linux/FreeBSD support it)

Somewhere in Ruby's build system something is inappropriately interpolating '$' characters in pathnames as either Makefile or shell variables. An example:

~~~
$ LDFLAGS=' -Wl,-rpath=\$$ORIGIN/../lib ' ./configure
$ make

$ readelf -d ruby|grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../lib:/usr/local/lib]

$ readelf -d .ext/x86_64-linux/strscan.so|grep RPATH
 0x000000000000000f (RPATH)              Library rpath: [\/../lib]
~~~

Note the differing RPATH values.

I'm able to nest escaping in the initial `LDFLAGS` argument in order to pass the correct value to `ruby`. However, extensions (including subsequently built rubygems) will read this path from the `ruby` binary and will not have correct quoting when constructing the extension build, which will cause the wrong RPATH to be set in all extension shared objects.

There are likely all sorts of special characters which trigger quoting issues in Ruby's build system, as is common in any Bourne shell / Makefile system. I'm primarily concerned with the '$' character as it is necessary to interact with linker macros -- which in turn are necessary to produce a relocatable Ruby binary with custom library dependencies.

I've verified this against trunk.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>