Repository: KhronosGroup/SPIRV-Tools (language: python)

Issue:
libSPIRV-Tools-opt.so contains reference to $srcdir
spirv-tools rev https://github.com/KhronosGroup/SPIRV-Tools/commit/27673a054447e37810a38e7ce8d35a0a88af4a75

When building https://aur.archlinux.org/packages/spirv-tools-git namcap emits a warning

`==> WARNING: Package contains reference to $srcdir
usr/lib/libSPIRV-Tools-opt.so
`

adding `CMAKE_SKIP_INSTALL_RPATH=YES` or `CMAKE_SKIP_RPATH=YES` to the build options doesn't make a difference .

The mentioned library does contain a reference to a local file .
```
$ strings libSPIRV-Tools-opt.so | grep "home"
/home/panoramix/Documents/Aur/pkgbuilds/spirv-tools-git/src/SPIRV-Tools/source/opt/type_manager.cpp
$ 
```






Discussion / hints:
Are you are building a release version? When I build a release version, I do not see references to the source directory. I notice lots of references when I build the debug version, which is probably in the dwarf info.
I am building latest trunk main version. Tested 2022.4 & 2023.2 releases, they don't have this issue.

Will try to bisect, though changes in build deps makes this hard(er)
I finally got back to this. I realized my problem. I was not building the shared libraries, so when I did `find . -name "*.so" | xargs strings | grep home` to search the shared libraries, it was not finding the libraries, and returning nothing.

I can now reproduce it. Now, I am able to see the string with the home directory in versions going back to v2021.1. Can you provide me with the exact cmake command you are using? There might still be some small differences.

Fix patch:
diff --git a/BUILD.bazel b/BUILD.bazel
index a2342770e7..b83fd5aead 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -456,7 +456,6 @@ cc_library(
     ],
     exclude = [
         "test/cpp_interface_test.cpp",
-        "test/log_test.cpp",
         "test/pch_test.cpp",
     ],
 )]
@@ -487,19 +486,6 @@ cc_test(
     ],
 )
 
-cc_test(
-    name = "base_log_test",
-    size = "small",
-    srcs = ["test/log_test.cpp"],
-    copts = TEST_COPTS,
-    linkstatic = 1,
-    deps = [
-        ":spirv_tools_opt_internal",
-        "@com_google_googletest//:gtest",
-        "@com_google_googletest//:gtest_main",
-    ],
-)
-
 cc_library(
     name = "link_test_lib",
     testonly = 1,
diff --git a/source/opt/log.h b/source/opt/log.h
index 68051002e2..4fb66fd455 100644
--- a/source/opt/log.h
+++ b/source/opt/log.h
@@ -23,7 +23,7 @@
 #include "spirv-tools/libspirv.hpp"
 
 // Asserts the given condition is true. Otherwise, sends a message to the
-// consumer and exits the problem with failure code. Accepts the following
+// consumer and exits the program with failure code. Accepts the following
 // formats:
 //
 // SPIRV_ASSERT(<message-consumer>, <condition-expression>);
@@ -36,7 +36,9 @@
 #if !defined(NDEBUG)
 #define SPIRV_ASSERT(consumer, ...) SPIRV_ASSERT_IMPL(consumer, __VA_ARGS__)
 #else
-#define SPIRV_ASSERT(consumer, ...)
+// Adding a use to avoid errors in the release build related to unused
+// consumers.
+#define SPIRV_ASSERT(consumer, ...) (void)(consumer)
 #endif
 
 // Logs a debug message to the consumer. Accepts the following formats:
@@ -49,26 +51,11 @@
 #if !defined(NDEBUG) && defined(SPIRV_LOG_DEBUG)
 #define SPIRV_DEBUG(consumer, ...) SPIRV_DEBUG_IMPL(consumer, __VA_ARGS__)
 #else
-#define SPIRV_DEBUG(consumer, ...)
+// Adding a use to avoid errors in the release build related to unused
+// consumers.
+#define SPIRV_DEBUG(consumer, ...) (void)(consumer)
 #endif
 
-// Logs an error message to the consumer saying the given feature is
-// unimplemented.
-#define SPIRV_UNIMPLEMENTED(consumer, feature)                \
-  do {                                                        \
-    spvtools::Log(consumer, SPV_MSG_INTERNAL_ERROR, __FILE__, \
-                  {static_cast<size_t>(__LINE__), 0, 0},      \
-                  "unimplemented: " feature);                 \
-  } while (0)
-
-// Logs an error message to the consumer saying the code location
-// should be unreachable.
-#define SPIRV_UNREACHABLE(consumer)                                      \
-  do {                                                                   \
-    spvtools::Log(consumer, SPV_MSG_INTERNAL_ERROR, __FILE__,            \
-                  {static_cast<size_t>(__LINE__), 0, 0}, "unreachable"); \
-  } while (0)
-
 // Helper macros for concatenating arguments.
 #define SPIRV_CONCATENATE(a, b) SPIRV_CONCATENATE_(a, b)
 #define SPIRV_CONCATENATE_(a, b) a##b
diff --git a/source/opt/type_manager.cpp b/source/opt/type_manager.cpp
index 2dcc25940c..ae320772df 100644
--- a/source/opt/type_manager.cpp
+++ b/source/opt/type_manager.cpp
@@ -901,7 +901,7 @@ Type* TypeManager::RecordIfTypeDefinition(const Instruction& inst) {
       type = new HitObjectNV();
       break;
     default:
-      SPIRV_UNIMPLEMENTED(consumer_, "unhandled type");
+      assert(false && "Type not handled by the type manager.");
       break;
   }
 
@@ -943,12 +943,10 @@ void TypeManager::AttachDecoration(const Instruction& inst, Type* type) {
       }
       if (Struct* st = type->AsStruct()) {
         st->AddMemberDecoration(index, std::move(data));
-      } else {
-        SPIRV_UNIMPLEMENTED(consumer_, "OpMemberDecorate non-struct type");
       }
     } break;
     default:
-      SPIRV_UNREACHABLE(consumer_);
+      assert(false && "Unexpected opcode for a decoration instruction.");
       break;
   }
 }


Test patch:
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 37c5e1d514..662c0bf4cb 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -111,7 +111,6 @@ set(TEST_SOURCES
   hex_float_test.cpp
   immediate_int_test.cpp
   libspirv_macros_test.cpp
-  log_test.cpp
   named_id_test.cpp
   name_mapper_test.cpp
   opcode_make_test.cpp
diff --git a/test/log_test.cpp b/test/log_test.cpp
deleted file mode 100644
index ec66aa1ece..0000000000
--- a/test/log_test.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2016 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "source/opt/log.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-namespace spvtools {
-namespace {
-
-using ::testing::MatchesRegex;
-
-TEST(Log, Unimplemented) {
-  int invocation = 0;
-  auto consumer = [&invocation](spv_message_level_t level, const char* source,
-                                const spv_position_t&, const char* message) {
-    ++invocation;
-    EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
-    EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
-    EXPECT_STREQ("unimplemented: the-ultimite-feature", message);
-  };
-
-  SPIRV_UNIMPLEMENTED(consumer, "the-ultimite-feature");
-  EXPECT_EQ(1, invocation);
-}
-
-TEST(Log, Unreachable) {
-  int invocation = 0;
-  auto consumer = [&invocation](spv_message_level_t level, const char* source,
-                                const spv_position_t&, const char* message) {
-    ++invocation;
-    EXPECT_EQ(SPV_MSG_INTERNAL_ERROR, level);
-    EXPECT_THAT(source, MatchesRegex(".*log_test.cpp$"));
-    EXPECT_STREQ("unreachable", message);
-  };
-
-  SPIRV_UNREACHABLE(consumer);
-  EXPECT_EQ(1, invocation);
-}
-
-}  // namespace
-}  // namespace spvtools