Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Libzstd: SHSTK not supported in cmake

Đang mở Phù hợp với người mới
#4,535 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, cmake
Lĩnh vực
build-system, security

Hướng nghiên cứu

Bắt đầu trong build/cmake/CMakeModules/AddZstdCompilationFlags.cmake, nơi các cờ biên dịch CMake được cấu hình cho các tệp assembly. Build libzstd bằng CMake trên một hệ thống x86-64, sau đó chạy readelf -n trên thư viện dùng chung tạo ra và kiểm tra thuộc tính SHSTK. Được xem là hoàn tất khi bản build CMake tạo ra một thư viện báo cáo cả IBT và SHSTK mà không làm hồi quy các bản build khác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

build

Problem description

SHSTK is an x64 security feature that is part of Intel CET, and support for it was added in PR #2992. The problem is, this PR only applies to the make build system, and not the cmake one, so when built with cmake, libzstd.so is still not marked as SHSTK-compatible, and this causes SHSTK not to be supported on applications that use libzstd.

How to reproduce

On systems that use cmake to build the library:

user@fedora:~$ readelf -n /usr/lib64/libzstd.so | grep SHSTK
... (no results) ...

Proposed fix

The crux of the issue is that when cmake compiles lib/decompress/huf_decompress_amd64.S, it doesn't pass any flags to the compiler. The object therefore gets compiled without -fcf-protection, which causes cet.h not to emit a .note.gnu.property section in the object, which in turn causes the final libzstd.so not to have that section either.

This can be fixed by simply using the C compiler flags when building assembly files, to ensure that -fcf-protection gets passed on them:

diff --git a/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake b/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
index 3e7bcce5..cddb7ceb 100644
--- a/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
+++ b/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
@@ -113,6 +113,9 @@ macro(ADD_ZSTD_COMPILATION_FLAGS _C _CXX _LD)
         endif ()
     endif ()
 
+    # Use the C flags as ASM flags
+    set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
+
     # Remove duplicates compilation flags
     foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
              CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO

Confirmed that it fixes the issue:

user@fedora:~$ readelf -n libzstd.so.1.5.7 | grep SHSTK
      Properties: x86 feature: IBT, SHSTK
Ngôn ngữ chính
C
Star
28.1k
Fork
2.7k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của facebook/zstd

Tất cả issue của facebook/zstd

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.