your programing

ld를 금으로 대체-경험이 있습니까?

lovepro 2020. 10. 12. 07:58
반응형

ld를 금으로 대체-경험이 있습니까?


누구든지 gold대신 사용하려고 ld했습니까?

gold 보다 훨씬 빠르기 ld때문에 대규모 C ++ 애플리케이션의 테스트주기를 가속화하는 데 도움이 될 수 있지만 ld의 드롭 인 대체물로 사용할 수 있습니까?

gcc/ g++직접 전화 gold.?

알려진 버그 나 문제점이 있습니까?

goldGNU binutils의 일부 이지만 웹에서 "성공 사례"나 "Howtos"조차 거의 발견하지 못했습니다.

( 업데이트 : 골드 링크 및이를 설명하는 블로그 항목 추가 )


현재 Ubuntu 10.04에서 더 큰 프로젝트를 컴파일하고 있습니다. 여기에서 binutils-gold패키지를 쉽게 설치하고 통합 할 수 있습니다 (해당 패키지를 제거하면 이전 버전을 얻게됩니다 ld). 그러면 Gcc는 자동으로 금을 사용합니다.

몇 가지 경험 :

  • 금은 검색하지 않습니다 /usr/local/lib
  • gold는 pthread 또는 rt와 같은 libs를 가정하지 않고 직접 추가해야했습니다.
  • 더 빠르고 더 적은 메모리가 필요합니다 (나중에 많은 부스트 ​​등이있는 큰 C ++ 프로젝트에서 중요합니다)

작동하지 않는 것 : 커널을 컴파일 할 수 없으므로 커널 모듈이 없습니다. Ubuntu는 fglrx와 같은 독점 드라이버를 업데이트하는 경우 DKMS를 통해이 작업을 자동으로 수행합니다. 이것은 실패합니다 ld-gold(골드를 제거하고 DKMS를 다시 시작하고 ld-gold.


골드를 선택적으로 사용하는 방법 (즉, 심볼릭 링크를 사용하는 시스템 전체가 아님)을 찾는 데 시간이 조금 걸렸으므로 여기에 솔루션을 게시하겠습니다. http://code.google.com/p/chromium/wiki/LinuxFasterBuilds#Linking_using_gold를 기반으로 합니다.

  1. 골드 글루 스크립트를 넣을 수있는 디렉토리를 만드십시오. 나는 ~/bin/gold/.
  2. 거기에 다음 접착제 스크립트를 넣고 이름을 지정하십시오 ~/bin/gold/ld.

    #!/bin/bash
    gold "$@"
    

    분명히 실행 가능하게 만드십시오 chmod a+x ~/bin/gold/ld.

  3. 에 통화 변경 gccgcc -B$HOME/bin/gold같은 도우미 프로그램에 대해, 지정된 디렉토리에 GCC 모양을 만드는 ld때문에 대신 시스템 기본의 접착제 스크립트를 사용을 ld.


gcc / g ++에서 gold를 직접 호출 할 수 있습니까?

답변을 보완하기 위해 gcc의 옵션이 있습니다 -fuse-ld=gold( gcc doc 참조 ). AFAIK는 옵션이 효과가없는 방식으로 빌드 중에 gcc를 구성 할 수 있습니다.


Samba 개발자로서 저는 몇 년 동안 거의 독점적으로 Ubuntu, Debian 및 Fedora에서 골드 링커를 사용하고 있습니다. 내 평가 :

  • 금은 고전적인 링커보다 몇 배 (느낌 : 5-10 배) 빠릅니다.
  • 처음에는 몇 가지 문제가 있었지만 대략 Ubuntu 12.04 이후로 사라졌습니다.
  • 골드 링커는 일부 세부 사항과 관련하여 고전적인 것보다 더 정확 해 보이기 때문에 우리 코드에서 일부 종속성 문제를 발견했습니다. 예를 들어이 Samba commit을 참조하십시오 .

나는 금을 선택적으로 사용하지 않았지만 배포가 제공하는 경우 심볼릭 링크 또는 대체 메커니즘을 사용하고 있습니다.


( 덮어 쓰기를 방지하기 위해 설치 한 경우 로컬 바이너리 디렉토리에) 링크 ldgold수 있습니다 ld.

ln -s `which gold` ~/bin/ld

또는

ln -s `which gold` /usr/local/bin/ld

최소 합성 벤치 마크

결과 : 금은 내가 시도한 모든 값에 대해 약 2 배에서 3 배 더 빠릅니다.

객체 생성

#!/usr/bin/env bash
set -eu

# CLI args.

# Each of those files contains n_ints_per_file ints.
n_int_file_is="${1:-10}"
n_ints_per_file="${2:-10}"

# Each function adds all ints from all files.
# This leads to n_int_file_is x n_ints_per_file x n_funcs relocations.
n_funcs="${3:-10}"

# Do a debug build, since it is for debug builds that link time matters the most,
# as the user will be recompiling often.
cflags='-ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic'

# Cleanup previous generated files objects.
./clean

# Generate i_*.c, ints.h and int_sum.h
rm -f ints.h
echo 'return' > int_sum.h
int_file_i=0
while [ "$int_file_i" -lt "$n_int_file_is" ]; do
  int_i=0
  int_file="${int_file_i}.c"
  rm -f "$int_file"
  while [ "$int_i" -lt "$n_ints_per_file" ]; do
    echo "${int_file_i} ${int_i}"
    int_sym="i_${int_file_i}_${int_i}"
    echo "unsigned int ${int_sym} = ${int_file_i};" >> "$int_file"
    echo "extern unsigned int ${int_sym};" >> ints.h
    echo "${int_sym} +" >> int_sum.h
    int_i=$((int_i + 1))
  done
  int_file_i=$((int_file_i + 1))
done
echo '1;' >> int_sum.h

# Generate funcs.h and main.c.
rm -f funcs.h
cat <<EOF >main.c
#include "funcs.h"

int main(void) {
return
EOF
i=0
while [ "$i" -lt "$n_funcs" ]; do
  func_sym="f_${i}"
  echo "${func_sym}() +" >> main.c
  echo "int ${func_sym}(void);" >> funcs.h
  cat <<EOF >"${func_sym}.c"
#include "ints.h"

int ${func_sym}(void) {
#include "int_sum.h"
}
EOF
  i=$((i + 1))
done
cat <<EOF >>main.c
1;
}
EOF

# Generate *.o
ls | grep -E '\.c$' | parallel --halt now,fail=1 -t --will-cite "gcc $cflags -c -o '{.}.o' '{}'"

GitHub 업스트림 .

다음 유형의 입력이 주어지면 :

./generate-objects [n_int_file_is [n_ints_per_file [n_funcs]]]

이것은 다음을 수행하는 메인을 생성합니다.

return f_0() + f_1() + ... + f_(n_funcs)()

각 함수는 별도의 f_n.c파일에 정의되고 n_int_file_is시간 n_ints_per_fileextern int를 추가합니다 .

int f_0() { return i_0_0 + i_0_1 + ... + i_(n_int_file_is)_(n_ints_per_file); }

이로 인해 :

n_int_file_is x n_ints_per_file x n_funcs

링크의 재배치 .

그런 다음 비교했습니다.

gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic               -o main *.o
gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic -fuse-ld=gold -o main *.o

다양한 입력 트리플렛에 대해 다음을 제공했습니다.

10000 10 10
nogold: wall=3.70s user=2.93s system=0.75s max_mem=556356kB
gold:   wall=1.43s user=1.15s system=0.28s max_mem=703060kB

1000 100 10
nogold: wall=1.23s user=1.07s system=0.16s max_mem=188152kB
gold:   wall=0.60s user=0.52s system=0.07s max_mem=279108kB

100 1000 10
nogold: wall=0.96s user=0.87s system=0.08s max_mem=149636kB
gold:   wall=0.53s user=0.47s system=0.05s max_mem=231596kB

10000 10 100
nogold: wall=11.63s user=10.31s system=1.25s max_mem=1411264kB
gold:   wall=6.31s user=5.77s system=0.53s max_mem=2146992kB

1000 100 100
nogold: wall=7.19s user=6.56s system=0.60s max_mem=1058432kB
gold:   wall=4.15s user=3.81s system=0.34s max_mem=1697796kB

100 1000 100
nogold: wall=6.15s user=5.58s system=0.57s max_mem=1031372kB
gold:   wall=4.06s user=3.76s system=0.29s max_mem=1652548kB

완화하려고 시도한 몇 가지 제한 :

  • 100k C 파일에서 두 방법 모두 때때로 실패한 malloc을 얻습니다.
  • GCC cannot compile a function with 1M additions

Tested on Ubuntu 18.10, GCC 8.2.0, Lenovo ThinkPad P51 laptop, Intel Core i7-7820HQ CPU (4 cores / 8 threads), 2x Samsung M471A2K43BB1-CRC RAM (2x 16GiB), Samsung MZVLB512HAJQ-000L7 SSD (3,000 MB/s).

I have also observed a 2x in the debug build of gem5: https://gem5.googlesource.com/public/gem5/+/fafe4e80b76e93e3d0d05797904c19928587f5b5


Some projects seem to be incompatible with gold, because of some incompatible differences between ld and gold. Example: OpenFOAM, see http://www.openfoam.org/mantisbt/view.php?id=685 .


DragonFlyBSD switched over to gold as their default linker. So it seems to be ready for a variety of tools.
More details: http://phoronix.com/scan.php?page=news_item&px=DragonFlyBSD-Gold-Linker

참고URL : https://stackoverflow.com/questions/3476093/replacing-ld-with-gold-any-experience

반응형