Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize liblzma.a build #107

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

NobodyXu
Copy link

  • Reduce liblzma.a size by using --gc-sections
  • Add new feat fat-lto and thin-lto to turn out fat and thin lto for building liblzma.a
  • Add new feat thin to optimize for size using macro HAVE_SMALL

Signed-off-by: Jiahao XU Jiahao_XU@outlook.com

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
…iblzma.a`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu marked this pull request as draft January 27, 2023 11:50
@NobodyXu
Copy link
Author

The CI seems to be broken by new feature thin:

  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-I" "xz-5.2/src/liblzma/api" "-I" "xz-5.2/src/liblzma/lzma" "-I" "xz-5.2/src/liblzma/lz" "-I" "xz-5.2/src/liblzma/check" "-I" "xz-5.2/src/liblzma/simple" "-I" "xz-5.2/src/liblzma/delta" "-I" "xz-5.2/src/liblzma/common" "-I" "xz-5.2/src/liblzma/rangecoder" "-I" "xz-5.2/src/common" "-I" "/home/runner/work/xz2-rs/xz2-rs/lzma-sys" "-Wall" "-Wextra" "-std=c99" "-pthread" "-ffunction-sections" "-fdata-sections" "-fmerge-all-constants" "-Wl,--gc-sections" "-flto" "-DHAVE_CONFIG_H=1" "-DHAVE_SMALL=1" "-o" "/home/runner/work/xz2-rs/xz2-rs/target/debug/build/lzma-sys-817308151459d6e7/out/xz-5.2/src/liblzma/check/crc64_fast.o" "-c" "xz-5.2/src/liblzma/check/crc64_fast.c"
  cargo:warning=xz-5.2/src/liblzma/check/crc64_fast.c: In function ‘lzma_crc64’:
  cargo:warning=xz-5.2/src/liblzma/check/crc64_fast.c:40:31: error: ‘lzma_crc64_table’ undeclared (first use in this function); did you mean ‘lzma_crc32_table’?
  cargo:warning=   40 |                         crc = lzma_crc64_table[0][*buf++ ^ A1(crc)] ^ S8(crc);
  cargo:warning=      |                               ^~~~~~~~~~~~~~~~
  cargo:warning=      |                               lzma_crc32_table
  cargo:warning=xz-5.2/src/liblzma/check/crc64_fast.c:40:31: note: each undeclared identifier is reported only once for each function it appears in

This is probably an upstream bug, since HAVE_THIN disables lzma_crc64_table and only keeps lzma_crc32_table here:

#ifdef HAVE_SMALL
extern uint32_t lzma_crc32_table[1][256];
extern void lzma_crc32_init(void);
#else
extern const uint32_t lzma_crc32_table[8][256];
extern const uint64_t lzma_crc64_table[4][256];
#endif

@NobodyXu
Copy link
Author

I think upgrading xz to latest v5.4.1 might fix this.

@NobodyXu
Copy link
Author

I think #108 might fix the error in this PR, so I would retry after that PR is merged.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@@ -74,6 +74,27 @@ fn main() {
}
}

build

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be gates behind OPT_LEVEL. Only after OPT_LEVEL = Some("3")?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this MR by name.... xz2 should also define NDEBUG when OPT_LEVEL is 3

https://github.com/xz-mirror/xz/blob/b69da6d4bb6bb11fc0cf066920791990d2b22a06/dos/config.h#L136

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this MR by name.... xz2 should also define NDEBUG when OPT_LEVEL is 3

I've added #define NDEBUG 1 to config.h.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be gates behind OPT_LEVEL. Only after OPT_LEVEL = Some("3")?

I'm not sure which line are you referring to.
The line you referenced does not contain anything related to opt-level or optimization flags.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
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