Skip to content

Commit d9a6cbe

Browse files
authored
[OSS-Fuzz] Fix static library linking needed for OSS-Fuzz (project-chip#35523)
* getting transitive libraries for static linking * Fixing commit * integrating comments
1 parent 22db90a commit d9a6cbe

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

build/config/linux/pkg-config.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def main():
142142
dest='dridriverdir')
143143
parser.add_option('--version-as-components', action='store_true',
144144
dest='version_as_components')
145+
parser.add_option('--static', action='store_true',
146+
dest='static')
145147
(options, args) = parser.parse_args()
146148

147149
# Make a list of regular expressions to strip out.
@@ -203,7 +205,13 @@ def main():
203205
sys.stdout.write(dridriverdir.strip())
204206
return
205207

206-
cmd = [options.pkg_config, "--cflags", "--libs"] + args
208+
cmd = [options.pkg_config, "--cflags", "--libs"]
209+
210+
if options.static:
211+
cmd.append("--static")
212+
213+
cmd.extend(args)
214+
207215
if options.debug:
208216
sys.stderr.write('Running: %s\n' % ' '.join(cmd))
209217

build/config/linux/pkg_config.gni

+11-2
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,19 @@ template("pkg_config") {
137137

138138
# Link libraries statically for OSS-Fuzz fuzzer build
139139
if (oss_fuzz) {
140+
# Output libs needed for static linking (direct + transitive/non-direct libs), we will re-execute the script to get those libs
141+
args += [ "--static" ]
142+
pkgresult_static = exec_script(pkg_config_script, args, "value")
140143
libs = []
141144
ldflags = [ "-Wl,-Bstatic" ]
142-
foreach(lib, pkgresult[3]) {
143-
ldflags += [ "-l$lib" ]
145+
foreach(lib, pkgresult_static[3]) {
146+
# dl(dynamic loading) lib is not needed for linking statically and its presence triggers errors.
147+
# example of errors:
148+
# ld.lld: error: undefined symbol: __dlsym
149+
# >>> referenced by dlsym.o:(dlsym) in archive /lib/x86_64-linux-gnu/libdl.a
150+
if (lib != "dl") {
151+
ldflags += [ "-l$lib" ]
152+
}
144153
}
145154
ldflags += [ "-Wl,-Bdynamic" ]
146155
lib_dirs = pkgresult[4]

0 commit comments

Comments
 (0)