fasterthanlime / feedback

An issue tracker for articles/series/videos at https://fasterthanli.me/
13 stars 0 forks source link

ld command changed what -rpath dose #291

Closed BadPseudonym closed 7 months ago

BadPseudonym commented 9 months ago

It happened on this page

Making our own executable packer part 5

Here's what the issue is

The ld argument -rpath in the article sets RUNPATH instead of RPATH. I have shown the error and how to fix is below.

$ ld -rpath '$ORIGIN' -pie --dynamic-linker /lib64/ld-linux-x86-64.so.2 hello-dl.o libmsg.so -o hello-dl
ld: hello-dl.o: warning: relocation against `msg' in read-only section `.text'
ld: warning: creating DT_TEXTREL in a PIE

$ readelf -d hello-dl

Dynamic section at offset 0x2eb0 contains 16 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libmsg.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
...

$ ld --disable-new-dtags -rpath '$ORIGIN' -pie --dynamic-linker /lib64/ld-linux-x86-64.so.2 hello-dl.o libmsg.so -o hello-dl
ld: hello-dl.o: warning: relocation against `msg' in read-only section `.text'
ld: warning: creating DT_TEXTREL in a PIE

$ readelf -d hello-dl

Dynamic section at offset 0x2ec0 contains 15 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libmsg.so]
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN]
...

credit: https://stackoverflow.com/questions/52018092/how-to-set-rpath-and-runpath-with-gcc-ld I am using a up-to-date Ubuntu 22.04.3 LTS on wsl2

fasterthanlime commented 7 months ago

I applied your fix, thanks!