btrfs-progs: build: fix linking with static libmount
The libmount dependency has been added in commit 61ecaff036
("btrfs-progs: build: add libmount dependency"), and static build got
broken. There are functions that do basically the same thing and also
share the name, which in turn fails at link time.
ld: /../lib64/libmount.a(libcommon_la-canonicalize.o): in function `canonicalize_dm_name':
util-linux-2.34/lib/canonicalize.c:58: multiple definition of `canonicalize_dm_name';
common/path-utils.static.o:btrfs-progs/common/path-utils.c:286: first defined here
In case the collision can be resolved by renaming, it's done
(canonicalize_path and parse_size). There are 2 symbols from selinux
that are substituted by a weak aliases during the static build.
There's one new warning due to use of getgrnam_r in libmount that
depends on dynamic linking and may not work properly with static build.
We're not using the related functions directly or indirectly, so it
should be safe to ignore the warnings.
ld: ../lib64/libmount.a(la-utils.o): in function `mnt_get_gid':
util-linux-2.34/libmount/src/utils.c:625: warning: Using 'getgrnam_r' in statically linked applications
+requires at runtime the shared libraries from the glibc version used for linking
Issue: #333
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
273380d98f
commit
922eaa7b54
18
Makefile
18
Makefile
|
@ -129,10 +129,18 @@ LIBS = $(LIBS_BASE) $(LIBS_CRYPTO)
|
|||
LIBBTRFS_LIBS = $(LIBS_BASE) $(LIBS_CRYPTO)
|
||||
|
||||
# Static compilation flags
|
||||
STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections
|
||||
STATIC_CFLAGS = $(CFLAGS) -ffunction-sections -fdata-sections -DSTATICBUILD=1
|
||||
STATIC_LDFLAGS = -static -Wl,--gc-sections
|
||||
STATIC_LIBS = $(STATIC_LIBS_BASE)
|
||||
|
||||
# Static build with libmount print some warnings due to usage of UID/GID
|
||||
# functions that require some glibc dynamic functionality at runtime.
|
||||
# The following can be ignored:
|
||||
# - mnt_get_gid using getgrnam_r
|
||||
# - mnt_get_uid using getpwnam_r
|
||||
# - mnt_get_username using getpwuid_r
|
||||
STATICWARNING = @echo " NOTE: warnings about getgrnam_r/mnt_get_uid/... are harmless, building"
|
||||
|
||||
# don't use FORTIFY with sparse because glibc with FORTIFY can
|
||||
# generate so many sparse errors that sparse stops parsing,
|
||||
# which masks real errors that we want to see.
|
||||
|
@ -541,6 +549,7 @@ endif
|
|||
|
||||
btrfs-%.static: btrfs-%.static.o $(static_objects) $(patsubst %.o,%.static.o,$(standalone_deps)) $(static_libbtrfs_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $@.o $(static_objects) \
|
||||
$(patsubst %.o, %.static.o, $($(subst -,_,$(subst .static,,$@)-objects))) \
|
||||
$(static_libbtrfs_objects) $(STATIC_LDFLAGS) \
|
||||
|
@ -559,6 +568,7 @@ btrfs: btrfs.o $(objects) $(cmds_objects) $(libs_static)
|
|||
|
||||
btrfs.static: btrfs.static.o $(static_objects) $(static_cmds_objects) $(static_libbtrfs_objects) $(static_libbtrfsutil_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
|
||||
|
||||
btrfs.box: btrfs.box.o $(objects) $(cmds_objects) $(progs_box_objects) $(libs_static)
|
||||
|
@ -567,6 +577,7 @@ btrfs.box: btrfs.box.o $(objects) $(cmds_objects) $(progs_box_objects) $(libs_st
|
|||
|
||||
btrfs.box.static: btrfs.box.static.o $(static_objects) $(static_cmds_objects) $(progs_box_static_objects) $(static_libbtrfs_objects) $(static_libbtrfsutil_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) $(STATIC_CFLAGS) -o $@ $^ $(btrfs_convert_libs) \
|
||||
$(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
|
||||
|
||||
|
@ -587,6 +598,7 @@ btrfsck: btrfs
|
|||
|
||||
btrfsck.static: btrfs.static
|
||||
@echo " [LN] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(LN_S) -f $^ $@
|
||||
|
||||
mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
|
||||
|
@ -595,6 +607,7 @@ mkfs.btrfs: $(mkfs_objects) $(objects) $(libs_static)
|
|||
|
||||
mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
|
||||
|
||||
btrfstune: btrfstune.o $(objects) $(libs_static)
|
||||
|
@ -603,6 +616,7 @@ btrfstune: btrfstune.o $(objects) $(libs_static)
|
|||
|
||||
btrfstune.static: btrfstune.static.o $(static_objects) $(static_libbtrfs_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
|
||||
|
||||
btrfs-image: $(image_objects) $(objects) $(libs_static)
|
||||
|
@ -611,6 +625,7 @@ btrfs-image: $(image_objects) $(objects) $(libs_static)
|
|||
|
||||
btrfs-image.static: $(static_image_objects) $(static_objects) $(static_libbtrfs_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)
|
||||
|
||||
btrfs-convert: $(convert_objects) $(objects) $(libs_static)
|
||||
|
@ -619,6 +634,7 @@ btrfs-convert: $(convert_objects) $(objects) $(libs_static)
|
|||
|
||||
btrfs-convert.static: $(static_convert_objects) $(static_objects) $(static_libbtrfs_objects)
|
||||
@echo " [LD] $@"
|
||||
$(STATICWARNING) $@
|
||||
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(btrfs_convert_libs) $(STATIC_LIBS)
|
||||
|
||||
quick-test: quick-test.o $(objects) $(libs)
|
||||
|
|
|
@ -141,7 +141,7 @@ static int cmd_device_add(const struct cmd_struct *cmd,
|
|||
goto error_out;
|
||||
}
|
||||
|
||||
path = canonicalize_path(argv[i]);
|
||||
path = path_canonicalize(argv[i]);
|
||||
if (!path) {
|
||||
error("could not canonicalize pathname '%s': %m",
|
||||
argv[i]);
|
||||
|
@ -426,7 +426,7 @@ static int cmd_device_scan(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
path = canonicalize_path(argv[i]);
|
||||
path = path_canonicalize(argv[i]);
|
||||
if (!path) {
|
||||
error("could not canonicalize path '%s': %m", argv[i]);
|
||||
ret = 1;
|
||||
|
@ -478,7 +478,7 @@ static int cmd_device_ready(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
path = canonicalize_path(argv[optind]);
|
||||
path = path_canonicalize(argv[optind]);
|
||||
if (!path) {
|
||||
error("could not canonicalize pathname '%s': %m",
|
||||
argv[optind]);
|
||||
|
@ -633,7 +633,7 @@ static int cmd_device_stats(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
*/
|
||||
const bool json = (bconf.output_format == CMD_FORMAT_JSON);
|
||||
|
||||
canonical_path = canonicalize_path(path);
|
||||
canonical_path = path_canonicalize(path);
|
||||
|
||||
/* No path when device is missing. */
|
||||
if (!canonical_path) {
|
||||
|
|
|
@ -319,7 +319,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
|
|||
continue;
|
||||
}
|
||||
close(fd);
|
||||
canonical_path = canonicalize_path((char *)tmp_dev_info->path);
|
||||
canonical_path = path_canonicalize((char *)tmp_dev_info->path);
|
||||
printf("\tdevid %4llu size %s used %s path %s\n",
|
||||
tmp_dev_info->devid,
|
||||
pretty_size_mode(tmp_dev_info->total_bytes, unit_mode),
|
||||
|
@ -935,13 +935,13 @@ static int cmd_filesystem_defrag(const struct cmd_struct *cmd,
|
|||
bconf_be_verbose();
|
||||
break;
|
||||
case 's':
|
||||
start = parse_size(optarg);
|
||||
start = parse_size_from_string(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
len = parse_size(optarg);
|
||||
len = parse_size_from_string(optarg);
|
||||
break;
|
||||
case 't':
|
||||
thresh = parse_size(optarg);
|
||||
thresh = parse_size_from_string(optarg);
|
||||
if (thresh > (u32)-1) {
|
||||
warning(
|
||||
"target extent size %llu too big, trimmed to %u",
|
||||
|
|
|
@ -411,7 +411,7 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
|
|||
if (!strcasecmp(argv[optind], "none"))
|
||||
size = -1ULL;
|
||||
else
|
||||
size = parse_size(argv[optind]);
|
||||
size = parse_size_from_string(argv[optind]);
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
if (compressed)
|
||||
|
|
|
@ -211,7 +211,7 @@ static int cmd_replace_start(const struct cmd_struct *cmd,
|
|||
}
|
||||
|
||||
srcdev = argv[optind];
|
||||
dstdev = canonicalize_path(argv[optind + 1]);
|
||||
dstdev = path_canonicalize(argv[optind + 1]);
|
||||
if (!dstdev) {
|
||||
error("cannot canonicalize path '%s': %m",
|
||||
argv[optind + 1]);
|
||||
|
|
|
@ -282,7 +282,7 @@ int path_is_reg_or_block_device(const char *filename)
|
|||
* Returns NULL on invalid input or malloc failure; Other failures
|
||||
* will be handled by the caller using the input pathname.
|
||||
*/
|
||||
char *canonicalize_dm_name(const char *ptname)
|
||||
char *path_canonicalize_dm_name(const char *ptname)
|
||||
{
|
||||
FILE *f;
|
||||
size_t sz;
|
||||
|
@ -313,7 +313,7 @@ char *canonicalize_dm_name(const char *ptname)
|
|||
* Returns NULL on invalid input or malloc failure; Other failures
|
||||
* will be handled by the caller using the input pathname.
|
||||
*/
|
||||
char *canonicalize_path(const char *path)
|
||||
char *path_canonicalize(const char *path)
|
||||
{
|
||||
char *canonical, *p;
|
||||
|
||||
|
@ -325,7 +325,7 @@ char *canonicalize_path(const char *path)
|
|||
return strdup(path);
|
||||
p = strrchr(canonical, '/');
|
||||
if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) {
|
||||
char *dm = canonicalize_dm_name(p + 1);
|
||||
char *dm = path_canonicalize(p + 1);
|
||||
|
||||
if (dm) {
|
||||
free(canonical);
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
char *canonicalize_dm_name(const char *ptname);
|
||||
char *canonicalize_path(const char *path);
|
||||
char *path_canonicalize_dm_name(const char *ptname);
|
||||
char *path_canonicalize(const char *path);
|
||||
|
||||
int arg_copy_path(char *dest, const char *src, int destlen);
|
||||
int path_cat_out(char *out, const char *p1, const char *p2);
|
||||
|
|
|
@ -627,7 +627,7 @@ int set_label(const char *btrfs_dev, const char *label)
|
|||
|
||||
/*
|
||||
* A not-so-good version fls64. No fascinating optimization since
|
||||
* no one except parse_size use it
|
||||
* no one except parse_size_from_string uses it
|
||||
*/
|
||||
static int fls64(u64 x)
|
||||
{
|
||||
|
@ -639,7 +639,7 @@ static int fls64(u64 x)
|
|||
return 64 - i;
|
||||
}
|
||||
|
||||
u64 parse_size(const char *s)
|
||||
u64 parse_size_from_string(const char *s)
|
||||
{
|
||||
char c;
|
||||
char *endptr;
|
||||
|
@ -2147,3 +2147,22 @@ out:
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef STATICBUILD
|
||||
|
||||
/*
|
||||
* libmount links with selinux that we don't use, the following symbols are
|
||||
* missing. Weak aliases allow to link.
|
||||
*/
|
||||
|
||||
__attribute__((weak)) int selinux_trans_to_raw_context(const char * trans, char ** rawp)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef void *security_context_t;
|
||||
__attribute__((weak)) void freecon(security_context_t con)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -77,7 +77,7 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mo
|
|||
const char *pretty_size_mode(u64 size, unsigned mode);
|
||||
|
||||
enum btrfs_csum_type parse_csum_type(const char *s);
|
||||
u64 parse_size(const char *s);
|
||||
u64 parse_size_from_string(const char *s);
|
||||
u64 parse_qgroupid(const char *p);
|
||||
u64 arg_strtou64(const char *str);
|
||||
int open_file_or_dir(const char *fname, DIR **dirstream);
|
||||
|
|
|
@ -1810,7 +1810,7 @@ int BOX_MAIN(convert)(int argc, char *argv[])
|
|||
packing = 0;
|
||||
break;
|
||||
case 'N':
|
||||
nodesize = parse_size(optarg);
|
||||
nodesize = parse_size_from_string(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
rollback = 1;
|
||||
|
|
|
@ -999,7 +999,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
|||
warning("--leafsize is deprecated, use --nodesize");
|
||||
/* fall through */
|
||||
case 'n':
|
||||
nodesize = parse_size(optarg);
|
||||
nodesize = parse_size_from_string(optarg);
|
||||
nodesize_forced = 1;
|
||||
break;
|
||||
case 'L':
|
||||
|
@ -1050,10 +1050,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
case 's':
|
||||
sectorsize = parse_size(optarg);
|
||||
sectorsize = parse_size_from_string(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
block_count = parse_size(optarg);
|
||||
block_count = parse_size_from_string(optarg);
|
||||
zero_end = 0;
|
||||
break;
|
||||
case 'V':
|
||||
|
|
Loading…
Reference in New Issue