open-dice 빌드

Sijin·2025년 8월 13일

open-dice 빌드

  • 레포지토리를 받고 빌드해보자
  • 빌드 방법은 readme에 나와있다
git clone https://github.com/google/open-dice.git

git submodule update --init --recursive
source bootstrap.sh
gn gen out

ninja -C out

빌드 결과물

  • 빌드하면 out 디렉토리가 생성된다
sijin@Sijin:~/open-dice/out$ tree -d -L 2
.
├── gen
│   ├── generate_open_dice_tools_python_distribution
│   ├── open_dice_build_venv
│   └── third_party
├── host_debug
│   ├── gen
│   └── obj
├── host_fuzz
│   ├── gen
│   └── obj
├── host_optimized
│   ├── gen
│   └── obj
├── obj
│   └── third_party
├── protocol_buffer
│   └── gen
├── python
│   ├── gen
│   └── obj
└── python-venv
    ├── bin
    ├── include
    ├── lib
    └── lib64 -> lib

26 directories
  • 주로 확인해봐야하는 부분은 host_debug, host_optimized, host_fuzz이다
    • 서로 다른 toolchian으로 빌드된 결과물들이다
host_debughost_optimizedhost_fuzz
용도debug용 빌드, test suite보안 취약점이나 버그 발견을 위한 Fuzzing 테스트용 빌드배포용 최적화 빌드
컴파일 옵션debug 정보 포함, sanitizer 활성화-fsanitize=fuzzer, AddressSanitizer 등크기/성능 최적화 (-Os 등)
포함 파일test용 실행파일, 디버그용 라이브러리 등fuzzing 관련 실행파일, fuzzing용 라이브러리 등메인 실행파일, 최적화된 라이브러리 등

toolchain

공통 설정

config("common_config") {
  include_dirs = [ "//include" ]

  # No language extensions, to promote portability.
  cflags_c = [
    "-Wvla",
    "-std=c99",
    "-pedantic",
  ]

  # Modern C++ for test and tooling.
  cflags_cc = [ "-std=c++20" ]
}
  • 모든 툴체인이 공용으로 사용하는 옵션들이다

host_debug

_host_debug = {
  # Pigweed의 clang_debug 툴체인을 기반으로 사용
  _toolchain_base = pw_target_toolchain_host.clang_debug
  
  defaults = {
    default_configs += [
      "//toolchains:common_config",      # 공통 설정
      "//toolchains:enable_sanitizers",  # 메모리 안전성 검사
    ]
  }
}
  • pigweed의 clang_debug toolchain을 사용한다
  • common_config와 sanitizer 속성을 사용한다

host_fuzz

_host_fuzz = {
  _toolchain_base = pw_target_toolchain_host.clang_debug
  
  defaults = {
    default_configs += [
      "//toolchains:common_config",      # 공통 설정
      "//toolchains:enable_sanitizers",  # 메모리 안전성 검사
      "//toolchains:enable_fuzzer",      # 퍼징 기능
    ]
  }
}
  • host_debug에서 enable_fuzzer만 추가되었다

host_optimized

_host_optimized = {
  # Pigweed의 크기 최적화 툴체인 사용
  _toolchain_base = pw_target_toolchain_host.clang_size_optimized
  
  defaults = {
    default_configs += [
      "//toolchains:common_config"  # 공통 설정만 (Sanitizer 없음)
    ]
  }
}
  • pigweed의 크기 최적화 툴체인을 사용한다
  • debug, fuzz 관련 옵션은 사용하지 않는다

sanitizer, fuzzer

config("enable_sanitizers") {
  cflags = [
    "-fsanitize=address,undefined,integer",  # 3가지 Sanitizer
    "-fsanitize-blacklist=$filter_path",     # 필터링 규칙
  ]
  ldflags = cflags  # 링킹 시에도 동일한 플래그
  inputs = [ "sanitize_filter.txt" ]  # 제외할 파일 목록
}

config("enable_fuzzer") {
  cflags = [
    "-fsanitize=fuzzer",           # libFuzzer 활성화
    "-O1",                         # 가벼운 최적화
    "-fno-omit-frame-pointer",     # 스택 트레이스 보존
    "-fno-optimize-sibling-calls", # 디버깅 정보 보존
  ]
}

toolchain 적용

https://github.com/google/open-dice/blob/main/BUILD.gn

group("default") {
  deps = [
    ":fuzzers(//toolchains:host_fuzz)",
    ":optimized_libs(//toolchains:host_optimized)",
    ":python.install",
    ":tests.run(//toolchains:host_debug)",
  ]
}
  • 이렇게 정의된 toolchain들은 root directory의 BUILD.gn에서 사용된다
  • (예시) :fuzzers(//toolchains:host_fuzz)
    • fuzzers 그룹의 타겟들을 host_fuzz toolchain으로 빌드하라는 의미

test 실행

sijin@Sijin:~/open-dice/out/host_debug/obj/test$ ./dice_test
INF  [==========] Running all tests.
INF  [ RUN      ] DiceTest.KnownAnswer
INF  [       OK ] DiceTest.KnownAnswer
INF  [ RUN      ] DiceTest.HashFail
INF  [       OK ] DiceTest.HashFail
INF  [ RUN      ] DiceTest.KdfFail
INF  [       OK ] DiceTest.KdfFail
INF  [ RUN      ] DiceTest.CertFail
INF  [       OK ] DiceTest.CertFail
INF  [ RUN      ] DiceTest.CertTooSmall
INF  [       OK ] DiceTest.CertTooSmall
INF  [ RUN      ] DiceTest.NoExtraneousOps
INF  [       OK ] DiceTest.NoExtraneousOps
INF  [ RUN      ] DiceTest.NoCertParamsPreservesCDIs
INF  [       OK ] DiceTest.NoCertParamsPreservesCDIs
INF  [==========] Done running all tests.
INF  [  PASSED  ] 7 test(s).
  • test도 잘 동작하는 것으로 보인다

0개의 댓글