Skip to content

Commit 710f5f2

Browse files
authored
Merge branch 'main' into dag-always-push-freeze
2 parents ecc56c7 + 1dfdd1e commit 710f5f2

File tree

111 files changed

+4840
-777
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4840
-777
lines changed

.github/workflows/libclang-python-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010
- 'main'
1111
paths:
1212
- 'clang/bindings/python/**'
13-
- 'clang/test/bindings/python/**'
1413
- 'clang/tools/libclang/**'
14+
- 'clang/CMakeList.txt'
1515
- '.github/workflows/libclang-python-tests.yml'
1616
- '.github/workflows/llvm-project-tests.yml'
1717
pull_request:
1818
paths:
1919
- 'clang/bindings/python/**'
20-
- 'clang/test/bindings/python/**'
2120
- 'clang/tools/libclang/**'
21+
- 'clang/CMakeList.txt'
2222
- '.github/workflows/libclang-python-tests.yml'
2323
- '.github/workflows/llvm-project-tests.yml'
2424

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,9 @@ Error RewriteInstance::discoverStorage() {
626626
NextAvailableAddress += BC->PageAlign;
627627
}
628628

629+
NewTextSegmentAddress = NextAvailableAddress;
630+
NewTextSegmentOffset = NextAvailableOffset;
631+
629632
if (!opts::UseGnuStack && !BC->IsLinuxKernel) {
630633
// This is where the black magic happens. Creating PHDR table in a segment
631634
// other than that containing ELF header is tricky. Some loaders and/or
@@ -652,6 +655,8 @@ Error RewriteInstance::discoverStorage() {
652655

653656
PHDRTableAddress = NextAvailableAddress;
654657
PHDRTableOffset = NextAvailableOffset;
658+
NewTextSegmentAddress = NextAvailableAddress;
659+
NewTextSegmentOffset = NextAvailableOffset;
655660

656661
// Reserve space for 3 extra pheaders.
657662
unsigned Phnum = Obj.getHeader().e_phnum;
@@ -664,14 +669,12 @@ Error RewriteInstance::discoverStorage() {
664669

665670
NextAvailableAddress += Phnum * sizeof(ELF64LEPhdrTy);
666671
NextAvailableOffset += Phnum * sizeof(ELF64LEPhdrTy);
667-
}
668672

669-
// Align at cache line.
670-
NextAvailableAddress = alignTo(NextAvailableAddress, 64);
671-
NextAvailableOffset = alignTo(NextAvailableOffset, 64);
673+
// Align at cache line.
674+
NextAvailableAddress = alignTo(NextAvailableAddress, 64);
675+
NextAvailableOffset = alignTo(NextAvailableOffset, 64);
676+
}
672677

673-
NewTextSegmentAddress = NextAvailableAddress;
674-
NewTextSegmentOffset = NextAvailableOffset;
675678
BC->LayoutStartAddress = NextAvailableAddress;
676679

677680
// Tools such as objcopy can strip section contents but leave header
@@ -4133,13 +4136,8 @@ void RewriteInstance::mapAllocatableSections(
41334136
}
41344137

41354138
if (SType == ST_READONLY) {
4136-
if (PHDRTableAddress) {
4137-
// Segment size includes the size of the PHDR area.
4138-
NewTextSegmentSize = NextAvailableAddress - PHDRTableAddress;
4139-
} else if (NewTextSegmentAddress) {
4140-
// Existing PHDR table would be updated.
4139+
if (NewTextSegmentAddress)
41414140
NewTextSegmentSize = NextAvailableAddress - NewTextSegmentAddress;
4142-
}
41434141
} else if (SType == ST_READWRITE) {
41444142
NewWritableSegmentSize = NextAvailableAddress - NewWritableSegmentAddress;
41454143
// Restore NextAvailableAddress if no new writable sections
@@ -4186,9 +4184,7 @@ void RewriteInstance::patchELFPHDRTable() {
41864184
// NOTE Currently .eh_frame_hdr appends to the last segment, recalculate
41874185
// last segments size based on the NextAvailableAddress variable.
41884186
if (!NewWritableSegmentSize) {
4189-
if (PHDRTableAddress)
4190-
NewTextSegmentSize = NextAvailableAddress - PHDRTableAddress;
4191-
else if (NewTextSegmentAddress)
4187+
if (NewTextSegmentAddress)
41924188
NewTextSegmentSize = NextAvailableAddress - NewTextSegmentAddress;
41934189
} else {
41944190
NewWritableSegmentSize = NextAvailableAddress - NewWritableSegmentAddress;
@@ -4201,15 +4197,9 @@ void RewriteInstance::patchELFPHDRTable() {
42014197
SmallVector<ELF64LEPhdrTy, 3> NewPhdrs;
42024198
ELF64LEPhdrTy NewPhdr;
42034199
NewPhdr.p_type = ELF::PT_LOAD;
4204-
if (PHDRTableAddress) {
4205-
NewPhdr.p_offset = PHDRTableOffset;
4206-
NewPhdr.p_vaddr = PHDRTableAddress;
4207-
NewPhdr.p_paddr = PHDRTableAddress;
4208-
} else {
4209-
NewPhdr.p_offset = NewTextSegmentOffset;
4210-
NewPhdr.p_vaddr = NewTextSegmentAddress;
4211-
NewPhdr.p_paddr = NewTextSegmentAddress;
4212-
}
4200+
NewPhdr.p_offset = NewTextSegmentOffset;
4201+
NewPhdr.p_vaddr = NewTextSegmentAddress;
4202+
NewPhdr.p_paddr = NewTextSegmentAddress;
42134203
NewPhdr.p_filesz = NewTextSegmentSize;
42144204
NewPhdr.p_memsz = NewTextSegmentSize;
42154205
NewPhdr.p_flags = ELF::PF_X | ELF::PF_R;
@@ -4270,7 +4260,7 @@ void RewriteInstance::patchELFPHDRTable() {
42704260
};
42714261

42724262
auto writeNewSegmentPhdrs = [&]() {
4273-
if (PHDRTableAddress || NewTextSegmentSize) {
4263+
if (NewTextSegmentSize) {
42744264
SmallVector<ELF64LE::Phdr, 3> NewPhdrs = createNewPhdrs();
42754265
OS.write(reinterpret_cast<const char *>(NewPhdrs.data()),
42764266
sizeof(ELF64LE::Phdr) * NewPhdrs.size());

clang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ if( CLANG_INCLUDE_TESTS )
530530
clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
531531
)
532532
add_subdirectory(test)
533+
add_subdirectory(bindings/python/tests)
533534

534535
if(CLANG_BUILT_STANDALONE)
535536
umbrella_lit_testsuite_end(check-all)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Test target to run Python test suite from main build.
2+
3+
# Avoid configurations including '-include' from interfering with
4+
# our tests by setting CLANG_NO_DEFAULT_CONFIG.
5+
add_custom_target(check-clang-python
6+
COMMAND ${CMAKE_COMMAND} -E env
7+
CLANG_NO_DEFAULT_CONFIG=1
8+
CLANG_LIBRARY_PATH=$<TARGET_FILE_DIR:libclang>
9+
"${Python3_EXECUTABLE}" -m unittest discover
10+
DEPENDS libclang
11+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
12+
13+
set(RUN_PYTHON_TESTS TRUE)
14+
set_target_properties(check-clang-python PROPERTIES FOLDER "Clang/Tests")
15+
16+
# Tests require libclang.so which is only built with LLVM_ENABLE_PIC=ON
17+
if(NOT LLVM_ENABLE_PIC)
18+
set(RUN_PYTHON_TESTS FALSE)
19+
endif()
20+
21+
# Do not try to run if libclang was built with sanitizers because
22+
# the sanitizer library will likely be loaded too late to perform
23+
# interception and will then fail.
24+
# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
25+
# portable so its easier just to not run the tests when building
26+
# with ASan.
27+
if(NOT LLVM_USE_SANITIZER STREQUAL "")
28+
set(RUN_PYTHON_TESTS FALSE)
29+
endif()
30+
31+
# Tests fail on Windows, and need someone knowledgeable to fix.
32+
# It's not clear whether it's a test or a valid binding problem.
33+
if(WIN32)
34+
set(RUN_PYTHON_TESTS FALSE)
35+
endif()
36+
37+
# The Python FFI interface is broken on AIX: https://bugs.python.org/issue38628.
38+
if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
39+
set(RUN_PYTHON_TESTS FALSE)
40+
endif()
41+
42+
# AArch64, Hexagon, and Sparc have known test failures that need to be
43+
# addressed.
44+
# SystemZ has broken Python/FFI interface:
45+
# https://reviews.llvm.org/D52840#1265716
46+
if(${LLVM_NATIVE_ARCH} MATCHES "^(AArch64|Hexagon|Sparc|SystemZ)$")
47+
set(RUN_PYTHON_TESTS FALSE)
48+
endif()
49+
50+
# Tests will fail if cross-compiling for a different target, as tests will try
51+
# to use the host Python3_EXECUTABLE and make FFI calls to functions in target
52+
# libraries.
53+
if(CMAKE_CROSSCOMPILING)
54+
# FIXME: Consider a solution that allows better control over these tests in
55+
# a crosscompiling scenario. e.g. registering them with lit to allow them to
56+
# be explicitly skipped via appropriate LIT_ARGS, or adding a mechanism to
57+
# allow specifying a python interpreter compiled for the target that could
58+
# be executed using qemu-user.
59+
message(WARNING "check-clang-python not added to check-all as these tests fail in a cross-build setup")
60+
set(RUN_PYTHON_TESTS FALSE)
61+
endif()
62+
63+
if(RUN_PYTHON_TESTS)
64+
set_property(GLOBAL APPEND PROPERTY
65+
LLVM_ALL_ADDITIONAL_TEST_TARGETS check-clang-python)
66+
endif()

0 commit comments

Comments
 (0)