> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> s390x 아키텍처용 ClickHouse를 소스에서 빌드하는 가이드

# Linux에서 s390x(zLinux)용 빌드

ClickHouse는 현재 s390x를 실험적으로 지원합니다.

<div id="building-clickhouse-for-s390x">
  ## s390x용 ClickHouse 빌드
</div>

s390x는 다른 플랫폼과 마찬가지로 OpenSSL을 정적 라이브러리로 빌드합니다. OpenSSL을 동적 라이브러리로 빌드하려면 CMake에 `-DENABLE_OPENSSL_DYNAMIC=1`을 전달해야 합니다.

이 지침은 호스트 머신이 Linux x86\_64/ARM이고 [빌드 지침](/ko/resources/develop-contribute/build/build)에 따라 네이티브 빌드에 필요한 모든 도구를 갖추고 있다고 가정합니다. 또한 호스트가 Ubuntu 22.04라고 가정하지만, 아래 지침은 Ubuntu 20.04에서도 작동합니다.

네이티브 빌드에 사용하는 도구를 설치하는 것 외에도, 다음 추가 패키지를 설치해야 합니다:

```bash theme={null}
apt-get mold
rustup target add s390x-unknown-linux-gnu
```

s390x용으로 빌드하려면 다음을 실행하십시오:

```bash theme={null}
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-s390x.cmake ..
ninja
```

<div id="running">
  ## 실행
</div>

에뮬레이션하려면 s390x용 QEMU user static binary가 필요합니다. Ubuntu에서는 다음과 같이 설치할 수 있습니다.

```bash theme={null}
apt-get install binfmt-support binutils-s390x-linux-gnu qemu-user-static
```

빌드가 완료되면 예를 들어 다음과 같이 바이너리를 실행할 수 있습니다:

```bash theme={null}
qemu-s390x-static -L /usr/s390x-linux-gnu ./programs/clickhouse local --query "Select 2"
2
```

<div id="debugging">
  ## 디버깅
</div>

LLDB를 설치합니다:

```bash theme={null}
apt-get install lldb-21
```

s390x 실행형을 디버그하려면 QEMU를 디버그 모드로 실행하여 clickhouse를 실행하세요:

```bash theme={null}
qemu-s390x-static -g 31338 -L /usr/s390x-linux-gnu ./clickhouse
```

다른 셸에서 LLDB를 실행해 attach한 후, `<Clickhouse Parent Directory>`와 `<build directory>`를 환경에 맞는 값으로 바꾸십시오.

```bash theme={null}
lldb-15
(lldb) target create ./clickhouse
Current executable set to '/<Clickhouse Parent Directory>/ClickHouse/<build directory>/programs/clickhouse' (s390x).
(lldb) settings set target.source-map <build directory> /<Clickhouse Parent Directory>/ClickHouse
(lldb) gdb-remote 31338
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x0000004020e74cd0
->  0x4020e74cd0: lgr    %r2, %r15
    0x4020e74cd4: aghi   %r15, -160
    0x4020e74cd8: xc     0(8,%r15), 0(%r15)
    0x4020e74cde: brasl  %r14, 275429939040
(lldb) b main
Breakpoint 1: 9 locations.
(lldb) c
Process 1 resuming
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
    frame #0: 0x0000004005cd9fc0 clickhouse`main(argc_=1, argv_=0x0000004020e594a8) at main.cpp:450:17
   447  #if !defined(FUZZING_MODE)
   448  int main(int argc_, char ** argv_)
   449  {
-> 450      inside_main = true;
   451      SCOPE_EXIT({ inside_main = false; });
   452
   453      /// PHDR 캐시는 쿼리 프로파일러가 안정적으로 동작하기 위해 필요합니다
```

<div id="visual-studio-code-integration">
  ## Visual Studio Code 통합
</div>

* 비주얼 디버깅을 위해 [CodeLLDB](https://github.com/vadimcn/vscode-lldb) 확장 기능이 필요합니다.
* [CMake Variants](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/variants.md)를 사용하는 경우, [Command Variable](https://github.com/rioj7/command-variable) 확장 기능이 동적 실행 구성에 도움이 될 수 있습니다.
* 백엔드가 LLVM 설치를 가리키도록 설정해야 합니다. 예: `"lldb.library": "/usr/lib/x86_64-linux-gnu/liblldb-21.so"`
* 시작하기 전에 clickhouse 실행형을 디버그 모드로 실행해야 합니다. (이를 자동화하는 `preLaunchTask`를 만들 수도 있습니다)

<div id="example-configurations">
  ### 구성 예시
</div>

<div id="cmake-variantsyaml">
  #### cmake-variants.yaml
</div>

```yaml theme={null}
buildType:
  default: relwithdebinfo
  choices:
    debug:
      short: Debug
      long: Emit debug information
      buildType: Debug
    release:
      short: Release
      long: Optimize generated code
      buildType: Release
    relwithdebinfo:
      short: RelWithDebInfo
      long: Release with Debug Info
      buildType: RelWithDebInfo
    tsan:
      short: MinSizeRel
      long: Minimum Size Release
      buildType: MinSizeRel

toolchain:
  default: default
  description: Select toolchain
  choices:
    default:
      short: x86_64
      long: x86_64
    s390x:
      short: s390x
      long: s390x
      settings:
        CMAKE_TOOLCHAIN_FILE: cmake/linux/toolchain-s390x.cmake
```

<div id="launchjson">
  #### launch.json
</div>

```json theme={null}
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "custom",
            "name": "(lldb) Launch s390x with qemu",
            "targetCreateCommands": ["target create ${command:cmake.launchTargetPath}"],
            "processCreateCommands": ["gdb-remote 2159"],
            "preLaunchTask": "Run ClickHouse"
        }
    ]
}
```

<div id="settingsjson">
  #### settings.json
</div>

이렇게 하면 서로 다른 빌드가 `build` 폴더 아래의 서로 다른 하위 폴더에 저장됩니다.

```json theme={null}
{
    "cmake.buildDirectory": "${workspaceFolder}/build/${buildKitVendor}-${buildKitVersion}-${variant:toolchain}-${variant:buildType}",
    "lldb.library": "/usr/lib/x86_64-linux-gnu/liblldb-21.so"
}
```

<div id="run-debugsh">
  #### run-debug.sh
</div>

```sh theme={null}
#! /bin/sh
echo 'Starting debugger session'
cd $1
qemu-s390x-static -g 2159 -L /usr/s390x-linux-gnu $2 $3 $4
```

<div id="tasksjson">
  #### tasks.json
</div>

컴파일된 실행형을 바이너리 옆의 `tmp` 폴더에서 `server` 모드로 실행하고, `programs/server/config.xml`의 구성을 사용하도록 하는 작업을 정의합니다.

```json theme={null}
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run ClickHouse",
            "type": "shell",
            "isBackground": true,
            "command": "${workspaceFolder}/.vscode/run-debug.sh",
            "args": [
                "${command:cmake.launchTargetDirectory}/tmp",
                "${command:cmake.launchTargetPath}",
                "server",
                "--config-file=${workspaceFolder}/programs/server/config.xml"
            ],
            "problemMatcher": [
                {
                    "pattern": [
                        {
                            "regexp": ".",
                            "file": 1,
                            "location": 2,
                            "message": 3
                        }
                    ],
                    "background": {
                        "activeOnStart": true,
                        "beginsPattern": "^Starting debugger session",
                        "endsPattern": ".*"
                    }
                }
            ]
        }
    ]
}
```
