Skip to content

Commit

Permalink
[OSS-Fuzz] Fix static library linking needed for OSS-Fuzz (#35523)
Browse files Browse the repository at this point in the history
* getting transitive libraries for static linking

* Fixing commit

* integrating comments
  • Loading branch information
Alami-Amine authored and pull[bot] committed Nov 4, 2024
1 parent 5f718f3 commit 7f64cab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion build/config/linux/pkg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def main():
dest='dridriverdir')
parser.add_option('--version-as-components', action='store_true',
dest='version_as_components')
parser.add_option('--static', action='store_true',
dest='static')
(options, args) = parser.parse_args()

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

cmd = [options.pkg_config, "--cflags", "--libs"] + args
cmd = [options.pkg_config, "--cflags", "--libs"]

if options.static:
cmd.append("--static")

cmd.extend(args)

if options.debug:
sys.stderr.write('Running: %s\n' % ' '.join(cmd))

Expand Down
13 changes: 11 additions & 2 deletions build/config/linux/pkg_config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ template("pkg_config") {

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

0 comments on commit 7f64cab

Please sign in to comment.