Skip to content

Fix XZ build when bundled LZMA header shadows liblzma#62

Open
xiongxianfei wants to merge 3 commits intodevttys0:masterfrom
xiongxianfei:fix-xz-lzma-header-shadowing
Open

Fix XZ build when bundled LZMA header shadows liblzma#62
xiongxianfei wants to merge 3 commits intodevttys0:masterfrom
xiongxianfei:fix-xz-lzma-header-shadowing

Conversation

@xiongxianfei
Copy link
Copy Markdown

Summary

This PR builds on #56 and fixes a long-standing XZ build failure where the bundled legacy LZMA SDK header shadows the system XZ Utils/liblzma header.

When both XZ_SUPPORT and legacy LZMA_SUPPORT are enabled, xz_wrapper.c includes <lzma.h> and expects the system liblzma header from liblzma-dev.

However, the Makefile adds bundled legacy LZMA include paths globally, including:

-I$(LZMA_ALT_DIR)

That can cause GCC to include:

./LZMA/lzmalt/lzma.h

instead of the system liblzma header:

/usr/include/lzma.h

The bundled legacy header does not define XZ/liblzma types such as lzma_vli, lzma_filter, and lzma_options_lzma, so the build fails.

Fix

This PR adds a small follow-up patch, patches/patch1.txt, and updates build.sh to apply all patch*.txt files in order.

The patch keeps legacy LZMA include paths for the legacy LZMA code, but removes them when compiling xz_wrapper.o, allowing <lzma.h> to resolve to the system liblzma header without hardcoding /usr/include/lzma.h.

Why not hardcode /usr/include/lzma.h?

Hardcoding this:

#include "/usr/include/lzma.h"

works on Ubuntu, but it is not portable to other Linux distributions, sysroots, cross-compilers, or custom install prefixes. Fixing the Makefile include path is more maintainable.

Tested

Tested with:

rm -rf squashfs4.3
./build.sh

cd squashfs4.3/squashfs-tools
make clean
make CC="gcc -H" > /tmp/sasquatch-build.log 2>&1
grep -i 'lzma.h' /tmp/sasquatch-build.log

Before:

./LZMA/lzmalt/lzma.h

After:

/usr/include/lzma.h

Also verified that the final binary links against liblzma:

ldd ./sasquatch | grep lzma

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants