Skip to content

Commit

Permalink
Revert "[nsan] Add nsan_preinit.cpp and make it static library only"
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Jul 11, 2024
1 parent 2ca3f87 commit 0b15f89
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
11 changes: 1 addition & 10 deletions compiler-rt/lib/nsan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ set(NSAN_SOURCES
nsan_suppressions.cpp
)

set(NSAN_PREINIT_SOURCES
nsan_preinit.cpp)

set(NSAN_HEADERS
nsan.h
nsan_flags.h
Expand Down Expand Up @@ -64,12 +61,6 @@ if(NOT APPLE)
ADDITIONAL_HEADERS ${NSAN_HEADERS}
CFLAGS ${NSAN_CFLAGS})

add_compiler_rt_object_libraries(RTNsan_preinit
ARCHS ${NSAN_SUPPORTED_ARCH}
SOURCES ${NSAN_PREINIT_SOURCES}
ADDITIONAL_HEADERS ${NSAN_HEADERS}
CFLAGS ${NSAN_CFLAGS})

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
add_compiler_rt_object_libraries(RTNsan_dynamic_version_script_dummy
ARCHS ${NSAN_SUPPORTED_ARCH}
Expand All @@ -81,7 +72,7 @@ add_compiler_rt_runtime(
clang_rt.nsan
STATIC
ARCHS ${NSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTNsan_preinit RTNsan
OBJECT_LIBS RTNsan
${NSAN_COMMON_RUNTIME_OBJECT_LIBS}
CFLAGS ${NSAN_CFLAGS}
PARENT_TARGET nsan)
Expand Down
7 changes: 6 additions & 1 deletion compiler-rt/lib/nsan/nsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_dump_shadow_args() {
bool __nsan::nsan_initialized;
bool __nsan::nsan_init_is_running;

extern "C" void __nsan_init() {
extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init() {
CHECK(!nsan_init_is_running);
if (nsan_initialized)
return;
Expand All @@ -801,3 +801,8 @@ extern "C" void __nsan_init() {
nsan_init_is_running = false;
nsan_initialized = true;
}

#if SANITIZER_CAN_USE_PREINIT_ARRAY
__attribute__((section(".preinit_array"),
used)) static void (*nsan_init_ptr)() = __nsan_init;
#endif
2 changes: 0 additions & 2 deletions compiler-rt/lib/nsan/nsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ using __sanitizer::uptr;
// Private nsan interface. Used e.g. by interceptors.
extern "C" {

void __nsan_init();

// This marks the shadow type of the given block of application memory as
// unknown.
// printf-free (see comment in nsan_interceptors.cc).
Expand Down
21 changes: 0 additions & 21 deletions compiler-rt/lib/nsan/nsan_preinit.cpp

This file was deleted.

3 comments on commit 0b15f89

@rorth
Copy link
Collaborator

@rorth rorth commented on 0b15f89 Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this commit broke the build on Linux/x86_64 (Ubuntu 20.04.6):

FAILED: lib/clang/19/lib/linux/libclang_rt.nsan-x86_64.so
[...]
usr/bin/ld: projects/compiler-rt/lib/nsan/CMakeFiles/RTNsan_dynamic.x86_64.dir/nsan.cpp.o: .preinit_array section is not allowed in DSO
/usr/bin/ld: failed to set dynamic section sizes: nonrepresentable section on output
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

/usr/bin/ld is GNU ld (GNU Binutils for Ubuntu) 2.34 (pretty old admittedly).

@dyung
Copy link
Collaborator

@dyung dyung commented on 0b15f89 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This revert also broke our internal Ubuntu22 based builders using the GNU linker. @MaskRay can you find a way to recommit this that doesn't break the sanitizers builder?

@MaskRay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This revert also broke our internal Ubuntu22 based builders using the GNU linker. @MaskRay can you find a way to recommit this that doesn't break the sanitizers builder?

@dyung Sorry for these linker issues. #98564 should have made sanitizer builds good.

Please sign in to comment.