Using Bin With High Glibc In Low Glibc Env

问题

众所周知,zip 在 Windows 下打包时使用了本地编码,但 Linux 下解压却使用 UTF-8 编码,导致中文乱码。

我有 unzipi,可以解决这个问题。但当我要在一台低版本 glibc 环境下运行时,我这用高版本构建的 unzipi 无法运行。

[demo@vmdeb ~]# unzipi
unzipi: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by unzipi)
unzipi: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by unzipi)

解决记录

上传高版本 libc.so.6,指定 glibc 路径

[demo@vmdeb ~]# LD_LIBRARY_PATH=/lib64/glibc233/ unzipi
unzipi: /lib64/ld-linux-x86-64.so.2: version `GLIBC_2.35' not found (required by /lib64/glibc233/libc.so.6)

仍然受限于 ld-linux-x86-64.so.2

上传高版本 ld-linux-x86-64.so.2,ld-linux 指定路径

将 unzipi 重命名为 unzipi.glibc233

编写脚本命名为 unzipi

#!/bin/bash

GLIBC_DIR=/lib64/glibc233
$GLIBC_DIR/ld-linux-x86-64.so.2 \
--library-path $GLIBC_DIR \
/bin/unzipi.glibc233 "$@"

再执行

[demo@vmdeb glibc233]# unzipi
/bin/unzipi.glibc233: error while loading shared libraries: libbz2.so.1.0: cannot open shared object file: No such file or directory

说明缺少 libbz2.so.1.0

软链接 libbz2.so.1.0

[demo@vmdeb glibc233]$ ls -alh
total 2.2M
drwxr-xr-x. 2 root root 72 Jun 27 22:46 .
dr-xr-xr-x. 48 root root 28K Jun 27 22:38 ..
-rwxr-xr-x. 1 root root 221K Jun 27 22:36 ld-linux-x86-64.so.2
lrwxrwxrwx. 1 root root 16 Jun 27 22:46 libbz2.so.1.0 -> ../libbz2.so.1.0
-rwxr-xr-x. 1 root root 2.0M Jun 27 22:36 libc.so.6

运行成功

[demo@vmdeb glibc233]# unzipi
UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).

-p extract files to pipe, no messages -l list files (short format)
-f freshen existing files, create none -t test compressed archive data
-u update files, create if necessary -z display archive comment only
-v list verbosely/show version info -T timestamp archive to latest
-x exclude files that follow (in xlist) -d extract files into exdir
modifiers:
-n never overwrite existing files -q quiet mode (-qq => quieter)
-o overwrite files WITHOUT prompting -a auto-convert any text files
-j junk paths (do not make directories) -aa treat ALL files as text
-U use escapes for all non-ASCII Unicode -UU ignore any Unicode fields
-C match filenames case-insensitively -L make (some) names lowercase
-X restore UID/GID info -V retain VMS version numbers
-K keep setuid/setgid/tacky permissions -M pipe through "more" pager

-O CHARSET specify a character encoding for DOS, Windows and OS/2 archives
-I CHARSET specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help. Examples:
unzip data1 -x joe => extract all files except joe from zipfile data1.zip
unzip -p foo | more => send contents of foo.zip via pipe into program more
unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer