[llvm] Remove -Wl, -z, defs linker flag when building shared libraries using llvm with emscripten (PR #123396)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 13:05:00 PST 2025


https://github.com/mcbarton created https://github.com/llvm/llvm-project/pull/123396

A project called CppInterOp makes use of llvm. When doing emscripten builds we get a warning that -Wl,-z,defs is not recognised (see
https://github.com/compiler-research/CppInterOp/actions/runs/12812649594/job/35724827621#step:9:214 ). It was determined that this flag was coming from here.

>From 5a2326dcdfd53ebfde92477944f44bac1084dd02 Mon Sep 17 00:00:00 2001
From: mcbarton <150042563+mcbarton at users.noreply.github.com>
Date: Fri, 17 Jan 2025 21:01:54 +0000
Subject: [PATCH] Remove -Wl,-z,defs linker flag when building shared libraries
 using llvm with emscripten

-Wl,-z,defs is not a recognised option when doing emscripten builds, and causes warnings in projects that utilise llvm
---
 llvm/cmake/modules/HandleLLVMOptions.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index f19125eb6bf273..9bb14ecae27489 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -309,7 +309,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
     message(WARNING "Build and install environment path info may be exposed; binaries will also be unrelocatable.")
   endif()
 endif()
-
+#ifndef EMSCRIPTEN
 # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
 # build might work on ELF but fail on MachO/COFF.
 if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|OS390" OR
@@ -317,7 +317,7 @@ if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|OS390" O
    NOT LLVM_USE_SANITIZER)
   set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
 endif()
-
+#endif
 # Pass -Wl,-z,nodelete. This makes sure our shared libraries are not unloaded
 # by dlclose(). We need that since the CLI API relies on cross-references
 # between global objects which became horribly broken when one of the libraries



More information about the llvm-commits mailing list