Skip to content

[libc] Fix macro definition hermeticity #114467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

michaelrj-google
Copy link
Contributor

Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.

Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.


Full diff: https://github.com/llvm/llvm-project/pull/114467.diff

3 Files Affected:

  • (modified) libc/include/llvm-libc-macros/linux/fcntl-macros.h (+3)
  • (modified) libc/test/src/sys/mman/linux/CMakeLists.txt (+1)
  • (modified) libc/test/src/sys/mman/linux/shm_test.cpp (+1-1)
diff --git a/libc/include/llvm-libc-macros/linux/fcntl-macros.h b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
index 8ee95863728e15..aec8a0d2da0b52 100644
--- a/libc/include/llvm-libc-macros/linux/fcntl-macros.h
+++ b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
@@ -88,6 +88,9 @@
 // Close on succesful
 #define F_CLOEXEC 1
 
+// Close on execute for fcntl.
+#define FD_CLOEXEC 1
+
 #define F_RDLCK 0
 #define F_WRLCK 1
 #define F_UNLCK 2
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index a432d88ffb90c9..69263986cc574c 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -163,5 +163,6 @@ add_libc_unittest(
     libc.src.unistd.ftruncate
     libc.src.unistd.close
     libc.src.__support.OSUtil.osutil
+    libc.hdr.fcntl_macros
     libc.test.UnitTest.ErrnoSetterMatcher
 )
diff --git a/libc/test/src/sys/mman/linux/shm_test.cpp b/libc/test/src/sys/mman/linux/shm_test.cpp
index 4b8971f670581c..97de705c4c2b06 100644
--- a/libc/test/src/sys/mman/linux/shm_test.cpp
+++ b/libc/test/src/sys/mman/linux/shm_test.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/fcntl_macros.h"
 #include "src/__support/OSUtil/syscall.h"
 #include "src/fcntl/fcntl.h"
 #include "src/sys/mman/mmap.h"
@@ -16,7 +17,6 @@
 #include "src/unistd/ftruncate.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"
 #include "test/UnitTest/LibcTest.h"
-#include <asm-generic/fcntl.h>
 #include <sys/syscall.h>
 
 using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

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

This is fine to unbreak the build for now.

Longer term, I think the linux specific libc/include/llvm-libc-macros/linux/fcntl-macros.h should be replaced with #include <asm-generic/fcntl.h>. We should not be redefining these ourselves IMO.

@nickdesaulniers nickdesaulniers merged commit e241964 into llvm:main Oct 31, 2024
7 of 8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 31, 2024

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building libc at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7857

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
0.605 [399/34/272] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_count_zeros_us.dir/stdc_count_zeros_us.cpp.o
0.606 [398/34/273] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_first_trailing_one_uc.dir/stdc_first_trailing_one_uc.cpp.o
0.606 [397/34/274] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_first_trailing_one_ull.dir/stdc_first_trailing_one_ull.cpp.o
0.606 [396/34/275] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_count_zeros_ui.dir/stdc_count_zeros_ui.cpp.o
0.607 [395/34/276] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.sscanf.dir/sscanf.cpp.o
0.607 [394/34/277] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_count_zeros_ul.dir/stdc_count_zeros_ul.cpp.o
0.610 [393/34/278] Building CXX object libc/src/stdio/gpu/CMakeFiles/libc.src.stdio.gpu.stderr.dir/stderr.cpp.o
0.613 [392/34/279] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vsscanf.dir/vsscanf.cpp.o
0.614 [391/34/280] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_count_zeros_ull.dir/stdc_count_zeros_ull.cpp.o
0.623 [390/34/281] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vscanf.dir/vscanf.cpp.o
FAILED: libc/src/stdio/CMakeFiles/libc.src.stdio.vscanf.dir/vscanf.cpp.o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc -isystem /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -DLIBC_COPT_SCANF_DISABLE_FLOAT -DLIBC_COPT_SCANF_DISABLE_INDEX_MODE -MD -MT libc/src/stdio/CMakeFiles/libc.src.stdio.vscanf.dir/vscanf.cpp.o -MF libc/src/stdio/CMakeFiles/libc.src.stdio.vscanf.dir/vscanf.cpp.o.d -o libc/src/stdio/CMakeFiles/libc.src.stdio.vscanf.dir/vscanf.cpp.o -c /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/vscanf.cpp
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/vscanf.cpp:11:
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/File/file.h:14:
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/CPP/new.h:17:10: fatal error: 'stdlib.h' file not found
   17 | #include <stdlib.h> // For malloc, free etc.
      |          ^~~~~~~~~~
1 error generated.
0.623 [390/33/282] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.vfscanf.dir/vfscanf.cpp.o
FAILED: libc/src/stdio/CMakeFiles/libc.src.stdio.vfscanf.dir/vfscanf.cpp.o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc -isystem /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -DLIBC_COPT_SCANF_DISABLE_FLOAT -DLIBC_COPT_SCANF_DISABLE_INDEX_MODE -MD -MT libc/src/stdio/CMakeFiles/libc.src.stdio.vfscanf.dir/vfscanf.cpp.o -MF libc/src/stdio/CMakeFiles/libc.src.stdio.vfscanf.dir/vfscanf.cpp.o.d -o libc/src/stdio/CMakeFiles/libc.src.stdio.vfscanf.dir/vfscanf.cpp.o -c /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/vfscanf.cpp
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/vfscanf.cpp:11:
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/File/file.h:14:
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/CPP/new.h:17:10: fatal error: 'stdlib.h' file not found
   17 | #include <stdlib.h> // For malloc, free etc.
      |          ^~~~~~~~~~
1 error generated.
0.624 [390/32/283] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.fscanf.dir/fscanf.cpp.o
FAILED: libc/src/stdio/CMakeFiles/libc.src.stdio.fscanf.dir/fscanf.cpp.o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc -isystem /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -DLIBC_COPT_SCANF_DISABLE_FLOAT -DLIBC_COPT_SCANF_DISABLE_INDEX_MODE -MD -MT libc/src/stdio/CMakeFiles/libc.src.stdio.fscanf.dir/fscanf.cpp.o -MF libc/src/stdio/CMakeFiles/libc.src.stdio.fscanf.dir/fscanf.cpp.o.d -o libc/src/stdio/CMakeFiles/libc.src.stdio.fscanf.dir/fscanf.cpp.o -c /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/fscanf.cpp
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/fscanf.cpp:11:
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/File/file.h:14:
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/CPP/new.h:17:10: fatal error: 'stdlib.h' file not found
   17 | #include <stdlib.h> // For malloc, free etc.
      |          ^~~~~~~~~~
1 error generated.
0.628 [390/31/284] Building CXX object libc/src/stdio/CMakeFiles/libc.src.stdio.scanf.dir/scanf.cpp.o
FAILED: libc/src/stdio/CMakeFiles/libc.src.stdio.scanf.dir/scanf.cpp.o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc -isystem /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -DLIBC_COPT_SCANF_DISABLE_FLOAT -DLIBC_COPT_SCANF_DISABLE_INDEX_MODE -MD -MT libc/src/stdio/CMakeFiles/libc.src.stdio.scanf.dir/scanf.cpp.o -MF libc/src/stdio/CMakeFiles/libc.src.stdio.scanf.dir/scanf.cpp.o.d -o libc/src/stdio/CMakeFiles/libc.src.stdio.scanf.dir/scanf.cpp.o -c /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/scanf.cpp
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/stdio/scanf.cpp:11:
In file included from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/File/file.h:14:
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/src/__support/CPP/new.h:17:10: fatal error: 'stdlib.h' file not found
   17 | #include <stdlib.h> // For malloc, free etc.
      |          ^~~~~~~~~~
1 error generated.
0.723 [390/30/285] Generating header locale.h from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/runtimes/../libc/newhdrgen/yaml/locale.yaml and /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/include/locale.h.def
0.727 [390/29/286] Generating /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/locale.h
0.751 [390/28/287] Generating header ctype.h from /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/runtimes/../libc/newhdrgen/yaml/ctype.yaml and /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/libc/include/ctype.h.def
0.763 [390/27/288] Generating /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/ctype.h

@michaelrj-google michaelrj-google deleted the libcFixMacros branch October 31, 2024 22:41
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants