[LU-8854] liblustre should not define strlcpy or strlcat Created: 18/Nov/16  Updated: 27/Feb/18  Resolved: 27/Feb/18

Status: Resolved
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: Lustre 2.11.0

Type: Bug Priority: Minor
Reporter: Patrick Farrell (Inactive) Assignee: Patrick Farrell (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Related
is related to LU-9897 Tracking of lustre library improvements. Open
Severity: 3
Rank (Obsolete): 9223372036854775807

 Description   

Currently, liblustre defines strlcpy and strlcat. This is problematic because some other libraries (which also shouldn't...) do this too, and then we can't link against them. (Notably, linking against SLURM libraries gets you libmunge, which defines them. So you can't link against liblustre and slurm.)

nm output for a recent-ish version of liblustre (the problem is the symbols marked "T", which are defined):
nm /lib64/liblustreapi.a | grep strl
U strlcat
U strlcpy
U strlen
U strlcpy
U strlen
U strlen
0000000000000060 T strlcat
0000000000000000 T strlcpy
U strlen

The solution is a fairly simple trick with #define, which lets us keep using the normal names without defining the symbols:
-size_t strlcpy(char *tgt, const char *src, size_t tgt_len);
+size_t ll_strlcpy(char *tgt, const char *src, size_t tgt_len);
+/* We must not export the strlcpy symbol from liblustre, hence this weirdness *
+#define strlcpy(a, b, c) ll_strlcpy(a, b, c)

Here's the resulting nm output:
nm ./lustre/utils/liblustreapi.a | grep strl
U ll_strlcat
U ll_strlcpy
U strlen
U ll_strlcpy
U strlen
U strlen
0000000000000000 T ll_strlcat
0000000000000090 T ll_strlcpy
U strlen

Patch coming shortly.



 Comments   
Comment by Gerrit Updater [ 18/Nov/16 ]

Patrick Farrell (paf@cray.com) uploaded a new patch: http://review.whamcloud.com/23869
Subject: LU-8854 liblustre: do not define strlcpy & strlcat
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: fcf24915cbe025b58072fe909f4018497fd4cdcb

Comment by James A Simmons [ 10/Aug/17 ]

Thank you for doing this. I have so been wanting to do this.

Comment by James A Simmons [ 23/Aug/17 ]

Thinking about this do we really need strlcpy and strlcat. snprintf(dst, len, "%s", src) = strlcpy() and snprintf(dst, len, "%s%s", src1, src2) = strlcat(). I think we could easily replace the occurrence with snprintf(..).

Comment by Gerrit Updater [ 26/Oct/17 ]

James Simmons (uja.ornl@yahoo.com) uploaded a new patch: https://review.whamcloud.com/29798
Subject: LU-8854 llapi: replace strlcpy & strlcat with lustre specific version
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: 28ca951f440ef9dbe286ef22f9890c8111cb29e4

Comment by Gerrit Updater [ 27/Feb/18 ]

Oleg Drokin (oleg.drokin@intel.com) merged in patch https://review.whamcloud.com/29798/
Subject: LU-8854 llapi: remove lustre specific strlcpy & strlcat functions
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: 971b0393a6d0e45051c9875efa2c7179cbf7d4c5

Comment by Peter Jones [ 27/Feb/18 ]

Landed for 2.11

Generated at Sat Feb 10 02:21:07 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.