Tar changes relative symlinks to absolute symlinks

梦想的初衷 提交于 2019-12-25 18:41:32

问题


To simplify the sysroot generation for cross compiling, I generate a tar file with relative symbolic links.

If I print the tar context with

tar tvf sysroot-libc6-dev.tar

then I get the correct result:

lrw-r--r-- jens/jens         1 2018-03-30 23:42 usr/lib/x86_64-linux-gnu/libBrokenLocale.so -> ../../../lib/x86_64-linux-gnu/libBrokenLocale.so.1
lrw-r--r-- jens/jens         1 2018-03-30 23:42 usr/lib/x86_64-linux-gnu/libanl.so -> ../../../lib/x86_64-linux-gnu/libanl.so.1
lrw-r--r-- jens/jens         1 2018-03-30 23:42 usr/lib/x86_64-linux-gnu/libcidn.so -> ../../../lib/x86_64-linux-gnu/libcidn.so.1

If I unpack the tar archive with

tar xvf sysroot-libc6-dev.tar

then the symlinks are absolute, this is a mess, because then the sysroot directory points to my host machine and cross compile will not work.

ls -al

lrwxrwxrwx 1 jens jens      33 Jan 14 11:39 libanl.so -> /lib/x86_64-linux-gnu/libanl.so.1
lrwxrwxrwx 1 jens jens      42 Jan 14 11:39 libBrokenLocale.so -> /lib/x86_64-linux-gnu/libBrokenLocale.so.1
lrwxrwxrwx 1 jens jens      34 Jan 14 11:39 libcidn.so -> /lib/x86_64-linux-gnu/libcidn.so.1

The purpose of the script is to keep everything relative, also the linker scripts, e.g. libc.so will be patched to relative links.

Thanks in advance

Jens Riebold


回答1:


I found the problem of my post. The tar will set relative links only if the destination of the symbolic link is also in the tar archive.

The problem with cross compiling for the raspberry pi are the absolute symbolic links to the libraries and the absolute paths in the ld scripts. (SO Files).

If you copy prebuild libraries from the raspberry pi into your cross compile project, then you have to fix that. It took me some time to understand the strange linker issues while working on my project.

The project works as follows:

sync_package.pl <debian package name>

The output is a tar file with relative links and relative pathes in the ld scripts.

Example:

sync_package.pl libmodbus-dev

Output:

sysroot-libmodbus-dev.tar


来源:https://stackoverflow.com/questions/49582114/tar-changes-relative-symlinks-to-absolute-symlinks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!