Skip to content

Commit

Permalink
Merge remote-tracking branch 'pingcap/master' into exchange-compress-…
Browse files Browse the repository at this point in the history
…revert-local-tunnel
  • Loading branch information
solotzg committed Jan 30, 2023
2 parents ac0c369 + c5558c4 commit 76a178a
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 13 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,12 @@ if (USE_STATIC_LIBRARIES)
list(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
endif ()

if (CMAKE_LIBRARY_ARCHITECTURE MATCHES "amd64.*|x86_64.*|AMD64.*")
if (ARCH_AMD64)
option (USE_INTERNAL_MEMCPY "Use internal implementation of 'memcpy' function instead of provided by libc. Only for x86_64." ON)

if (OS_LINUX)
option (GLIBC_COMPATIBILITY "Set to TRUE to enable compatibility with older glibc libraries. Only for x86_64, Linux. Implies USE_INTERNAL_MEMCPY." ON)
endif()
endif ()

if (GLIBC_COMPATIBILITY)
set (USE_INTERNAL_MEMCPY ON)
if ((ARCH_AMD64 OR ARCH_AARCH64) AND OS_LINUX)
option (GLIBC_COMPATIBILITY "Set to TRUE to enable compatibility with older glibc libraries. Only for x86_64, Linux. Implies USE_INTERNAL_MEMCPY." ON)
endif ()

option (PIPE "-pipe compiler option [less /tmp usage, more ram usage]" ON)
Expand Down
24 changes: 19 additions & 5 deletions libs/libglibc-compatibility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,34 @@

enable_language (ASM)

if (ARCH_AARCH64)
list (APPEND glibc_compatibility_sources musl/aarch64/syscall.s musl/aarch64/longjmp.s)
elseif (ARCH_AMD64)
list (APPEND glibc_compatibility_sources musl/x86_64/syscall.s musl/x86_64/longjmp.s)
else ()
message (FATAL_ERROR "glibc_compatibility can only be used on x86_64 or aarch64.")
endif ()

add_library (glibc-compatibility glibc-compatibility.c
musl/pipe2.c
musl/fallocate.c
musl/longjmp.s
musl/vasprintf.c
musl/lgamma.c
musl/posix_spawn.c
musl/futimens.c
musl/syscall.s
musl/syscall_ret.c
musl/sched_cpucount.c)
musl/sched_cpucount.c
${glibc_compatibility_sources})

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set_source_files_properties(musl/longjmp.s musl/syscall.s
PROPERTIES COMPILE_FLAGS -Wno-unused-command-line-argument)
if (ARCH_AARCH64)
set_source_files_properties(musl/aarch64/longjmp.s musl/aarch64/syscall.s
PROPERTIES COMPILE_FLAGS -Wno-unused-command-line-argument)
elseif (ARCH_AMD64)
set_source_files_properties(musl/x86_64/longjmp.s musl/x86_64/syscall.s
PROPERTIES COMPILE_FLAGS -Wno-unused-command-line-argument)
else ()
message(FATAL_ERROR "glibc_compatibility can only be used on x86_64 or aarch64.")
endif ()
endif()
add_subdirectory (tests EXCLUDE_FROM_ALL)
6 changes: 5 additions & 1 deletion libs/libglibc-compatibility/glibc-compatibility.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ extern "C" {

#include <pthread.h>

// We can not remove this function before manually designating the signal stack.
// However, the returned value could be set to 16KiB, so that we can save many VSZ.
// Morever, though we can use SIGSTKSZ to define the size of signal stack,
// it's too small to collect enough information.
size_t __pthread_get_minstack(const pthread_attr_t * attr)
{
return 1048576; /// This is a guess. Don't sure it is correct.
return 16384;
}

#include <signal.h>
Expand Down
35 changes: 35 additions & 0 deletions libs/libglibc-compatibility/musl/aarch64/longjmp.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2022 PingCAP, Ltd.
//
// 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.

.global musl_glibc_longjmp
.type musl_glibc_longjmp,@function
musl_glibc_longjmp:
// IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers
ldp x19, x20, [x0,#0]
ldp x21, x22, [x0,#16]
ldp x23, x24, [x0,#32]
ldp x25, x26, [x0,#48]
ldp x27, x28, [x0,#64]
ldp x29, x30, [x0,#80]
ldr x2, [x0,#104]
mov sp, x2
ldp d8 , d9, [x0,#112]
ldp d10, d11, [x0,#128]
ldp d12, d13, [x0,#144]
ldp d14, d15, [x0,#160]

mov x0, x1
cbnz x1, 1f
mov x0, #1
1: br x30
28 changes: 28 additions & 0 deletions libs/libglibc-compatibility/musl/aarch64/syscall.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 PingCAP, Ltd.
//
// 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.

.global __syscall
.hidden __syscall
.type __syscall,%function
__syscall:
uxtw x8,w0
mov x0,x1
mov x1,x2
mov x2,x3
mov x3,x4
mov x4,x5
mov x5,x6
mov x6,x7
svc 0
ret
File renamed without changes.
File renamed without changes.

0 comments on commit 76a178a

Please sign in to comment.