SERVER-72324 switch to toolchain lld linker.

This commit is contained in:
Daniel Moody 2022-12-29 21:17:27 +00:00 committed by Evergreen Agent
parent 96573561ca
commit 258f77aba1
10 changed files with 137 additions and 125 deletions

View File

@ -1251,6 +1251,18 @@ env_vars.Add(
default="14.3",
)
env_vars.Add(
'LINKFLAGS_COMPILER_EXEC_PREFIX',
help='Specify the search path to be injected into the LINKFLAGS',
default="",
)
env_vars.Add(
'COMPILER_EXEC_PREFIX_OPT',
help='Specify the option sign for compiler exec search paths.',
default="-B",
)
env_vars.Add(
'NINJA_BUILDDIR',
help="Location for shared Ninja state",
@ -1694,6 +1706,9 @@ def CheckDevEnv(context):
return result
env.Append(
LINKFLAGS=['${_concat(COMPILER_EXEC_PREFIX_OPT, LINKFLAGS_COMPILER_EXEC_PREFIX, "", __env__)}'])
devenv_check = Configure(
env,
help=False,
@ -3432,22 +3447,11 @@ def doConfigure(myenv):
linker_ld = get_option('linker')
if linker_ld == 'auto':
# lld has problems with separate debug info on some platforms. See:
# - https://bugzilla.mozilla.org/show_bug.cgi?id=1485556
# - https://bugzilla.mozilla.org/show_bug.cgi?id=1485556
#
# lld also apparently has problems with symbol resolution
# in some esoteric configurations that apply for us when
# using --link-model=dynamic mode, so disable lld there
# too. See:
# - https://bugs.llvm.org/show_bug.cgi?id=46676
#
# We should revisit all of these issues the next time we upgrade our clang minimum.
if get_option('separate-debug') == 'off' and get_option('link-model') != 'dynamic':
if not env.TargetOSIs('darwin', 'macOS'):
if not myenv.AddToLINKFLAGSIfSupported('-fuse-ld=lld'):
myenv.AddToLINKFLAGSIfSupported('-fuse-ld=gold')
else:
myenv.AddToLINKFLAGSIfSupported('-fuse-ld=gold')
myenv.FatalError(
f"The recommended linker 'lld' is not supported with the current compiler configuration, you can try the 'gold' linker with '--linker=gold'."
)
elif link_model.startswith("dynamic") and linker_ld == 'bfd':
# BFD is not supported due to issues with it causing warnings from some of
# the third party libraries that mongodb is linked with:

View File

@ -2103,6 +2103,7 @@ buildvariants:
-j3
--variables-files=etc/scons/mongodbtoolchain_stable_gcc.vars
--link-model=dynamic
--linker=gold
resmoke_jobs_max: 2
has_packages: true
packager_script: packager_enterprise.py

View File

@ -98,6 +98,7 @@ buildvariants:
MONGO_DISTMOD=rhel72
-j3
--variables-files=etc/scons/mongodbtoolchain_stable_gcc.vars
--linker=gold
crypt_task_compile_flags: >-
SHLINKFLAGS_EXTRA="-Wl,-Bsymbolic
-Wl,--no-gnu-unique"
@ -160,6 +161,7 @@ buildvariants:
MONGO_DISTMOD=rhel83
-j3
--variables-files=etc/scons/mongodbtoolchain_stable_gcc.vars
--linker=gold
crypt_task_compile_flags: >-
SHLINKFLAGS_EXTRA="-Wl,-Bsymbolic -Wl,--no-gnu-unique"
CCFLAGS="-fno-gnu-unique"

View File

@ -18,6 +18,12 @@ ENV = {
'PATH' : os.pathsep.join([toolchain_bindir] + default_path)
}
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
LINKFLAGS_COMPILER_EXEC_PREFIX = f'{toolchain_bindir}'
# Set any Variables for Tools from the toolchain here. Technically, we
# shouldn't need the full paths since SCons will find the toolchain
# ones first, but we don't want to accidentally get the system version

View File

@ -18,6 +18,11 @@ ENV = {
'PATH' : os.pathsep.join([toolchain_bindir] + default_path)
}
# TODO BUILD-16594
# This is temporary workaround so that gcc can find the LLVM lld from the toolchain
# until we can build this into the toolchain's default search paths
LINKFLAGS_COMPILER_EXEC_PREFIX = f'{toolchain_bindir}'
# Set any Variables for Tools from the toolchain here. Technically, we
# shouldn't need the full paths since SCons will find the toolchain
# ones first, but we don't want to accidentally get the system version

View File

@ -34,22 +34,21 @@ fi
#
echo "Running Mongo Crypt Shared Library exported symbols test"
expect='A MONGO_CRYPT_1.0
T mongo_crypt_v1_analyze_query
T mongo_crypt_v1_bson_free
T mongo_crypt_v1_get_version
T mongo_crypt_v1_get_version_str
T mongo_crypt_v1_lib_create
T mongo_crypt_v1_lib_destroy
T mongo_crypt_v1_query_analyzer_create
T mongo_crypt_v1_query_analyzer_destroy
T mongo_crypt_v1_status_create
T mongo_crypt_v1_status_destroy
T mongo_crypt_v1_status_get_code
T mongo_crypt_v1_status_get_error
T mongo_crypt_v1_status_get_explanation'
expect='mongo_crypt_v1_analyze_query@@MONGO_CRYPT_1.0
mongo_crypt_v1_bson_free@@MONGO_CRYPT_1.0
mongo_crypt_v1_get_version@@MONGO_CRYPT_1.0
mongo_crypt_v1_get_version_str@@MONGO_CRYPT_1.0
mongo_crypt_v1_lib_create@@MONGO_CRYPT_1.0
mongo_crypt_v1_lib_destroy@@MONGO_CRYPT_1.0
mongo_crypt_v1_query_analyzer_create@@MONGO_CRYPT_1.0
mongo_crypt_v1_query_analyzer_destroy@@MONGO_CRYPT_1.0
mongo_crypt_v1_status_create@@MONGO_CRYPT_1.0
mongo_crypt_v1_status_destroy@@MONGO_CRYPT_1.0
mongo_crypt_v1_status_get_code@@MONGO_CRYPT_1.0
mongo_crypt_v1_status_get_error@@MONGO_CRYPT_1.0
mongo_crypt_v1_status_get_explanation@@MONGO_CRYPT_1.0'
actual="$(nm --extern-only --defined-only "$SOPATH" | awk '{ print $2, $3 }' | sort)"
actual="$(readelf -W --dyn-syms "$SOPATH" | awk '$5 == "GLOBAL" && $7 != "UND" && $7 != "ABS" {print $(NF)}' | sort)"
if [ "$actual" != "$expect" ]; then
echo "Error: symbols are not as expected in: $SOPATH"

View File

@ -30,38 +30,33 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
extern "C" {
#endif
#include <inttypes.h>
#include <sys/types.h>
#include <inttypes.h>
#include <ucontext.h>
#define UNW_TARGET x86
#define UNW_TARGET_X86 1
#define UNW_TARGET x86
#define UNW_TARGET_X86 1
#define _U_TDEP_QP_TRUE 0 /* see libunwind-dynamic.h */
#define _U_TDEP_QP_TRUE 0 /* see libunwind-dynamic.h */
/* This needs to be big enough to accommodate "struct cursor", while
leaving some slack for future expansion. Changing this value will
require recompiling all users of this library. Stack allocation is
relatively cheap and unwind-state copying is relatively rare, so we
want to err on making it rather too big than too small. */
#define UNW_TDEP_CURSOR_LEN 127
#define UNW_TDEP_CURSOR_LEN 127
typedef uint32_t unw_word_t;
typedef int32_t unw_sword_t;
typedef union {
struct {
uint8_t b[4];
} val32;
struct {
uint8_t b[10];
} val80;
struct {
uint8_t b[16];
} val128;
struct { uint8_t b[4]; } val32;
struct { uint8_t b[10]; } val80;
struct { uint8_t b[16]; } val128;
} unw_tdep_fpreg_t;
typedef enum {
typedef enum
{
/* Note: general registers are expected to start with index 0.
This convention facilitates architecture-independent
implementation of the C++ exception handling ABI. See
@ -77,110 +72,115 @@ typedef enum {
DWARF, but that doesn't work because the libunwind requires
that the exception argument registers be consecutive, which the
wouldn't be with the DWARF numbering. */
UNW_X86_EAX, /* scratch (exception argument 1) */
UNW_X86_EDX, /* scratch (exception argument 2) */
UNW_X86_ECX, /* scratch */
UNW_X86_EBX, /* preserved */
UNW_X86_ESI, /* preserved */
UNW_X86_EDI, /* preserved */
UNW_X86_EBP, /* (optional) frame-register */
UNW_X86_ESP, /* (optional) frame-register */
UNW_X86_EIP, /* frame-register */
UNW_X86_EFLAGS, /* scratch (except for "direction", which is fixed */
UNW_X86_TRAPNO, /* scratch */
UNW_X86_EAX, /* scratch (exception argument 1) */
UNW_X86_EDX, /* scratch (exception argument 2) */
UNW_X86_ECX, /* scratch */
UNW_X86_EBX, /* preserved */
UNW_X86_ESI, /* preserved */
UNW_X86_EDI, /* preserved */
UNW_X86_EBP, /* (optional) frame-register */
UNW_X86_ESP, /* (optional) frame-register */
UNW_X86_EIP, /* frame-register */
UNW_X86_EFLAGS, /* scratch (except for "direction", which is fixed */
UNW_X86_TRAPNO, /* scratch */
/* MMX/stacked-fp registers */
UNW_X86_ST0, /* fp return value */
UNW_X86_ST1, /* scratch */
UNW_X86_ST2, /* scratch */
UNW_X86_ST3, /* scratch */
UNW_X86_ST4, /* scratch */
UNW_X86_ST5, /* scratch */
UNW_X86_ST6, /* scratch */
UNW_X86_ST7, /* scratch */
UNW_X86_ST0, /* fp return value */
UNW_X86_ST1, /* scratch */
UNW_X86_ST2, /* scratch */
UNW_X86_ST3, /* scratch */
UNW_X86_ST4, /* scratch */
UNW_X86_ST5, /* scratch */
UNW_X86_ST6, /* scratch */
UNW_X86_ST7, /* scratch */
UNW_X86_FCW, /* scratch */
UNW_X86_FSW, /* scratch */
UNW_X86_FTW, /* scratch */
UNW_X86_FOP, /* scratch */
UNW_X86_FCS, /* scratch */
UNW_X86_FIP, /* scratch */
UNW_X86_FEA, /* scratch */
UNW_X86_FDS, /* scratch */
UNW_X86_FCW, /* scratch */
UNW_X86_FSW, /* scratch */
UNW_X86_FTW, /* scratch */
UNW_X86_FOP, /* scratch */
UNW_X86_FCS, /* scratch */
UNW_X86_FIP, /* scratch */
UNW_X86_FEA, /* scratch */
UNW_X86_FDS, /* scratch */
/* SSE registers */
UNW_X86_XMM0_lo, /* scratch */
UNW_X86_XMM0_hi, /* scratch */
UNW_X86_XMM1_lo, /* scratch */
UNW_X86_XMM1_hi, /* scratch */
UNW_X86_XMM2_lo, /* scratch */
UNW_X86_XMM2_hi, /* scratch */
UNW_X86_XMM3_lo, /* scratch */
UNW_X86_XMM3_hi, /* scratch */
UNW_X86_XMM4_lo, /* scratch */
UNW_X86_XMM4_hi, /* scratch */
UNW_X86_XMM5_lo, /* scratch */
UNW_X86_XMM5_hi, /* scratch */
UNW_X86_XMM6_lo, /* scratch */
UNW_X86_XMM6_hi, /* scratch */
UNW_X86_XMM7_lo, /* scratch */
UNW_X86_XMM7_hi, /* scratch */
UNW_X86_XMM0_lo, /* scratch */
UNW_X86_XMM0_hi, /* scratch */
UNW_X86_XMM1_lo, /* scratch */
UNW_X86_XMM1_hi, /* scratch */
UNW_X86_XMM2_lo, /* scratch */
UNW_X86_XMM2_hi, /* scratch */
UNW_X86_XMM3_lo, /* scratch */
UNW_X86_XMM3_hi, /* scratch */
UNW_X86_XMM4_lo, /* scratch */
UNW_X86_XMM4_hi, /* scratch */
UNW_X86_XMM5_lo, /* scratch */
UNW_X86_XMM5_hi, /* scratch */
UNW_X86_XMM6_lo, /* scratch */
UNW_X86_XMM6_hi, /* scratch */
UNW_X86_XMM7_lo, /* scratch */
UNW_X86_XMM7_hi, /* scratch */
UNW_X86_MXCSR, /* scratch */
UNW_X86_MXCSR, /* scratch */
/* segment registers */
UNW_X86_GS, /* special */
UNW_X86_FS, /* special */
UNW_X86_ES, /* special */
UNW_X86_DS, /* special */
UNW_X86_SS, /* special */
UNW_X86_CS, /* special */
UNW_X86_TSS, /* special */
UNW_X86_LDT, /* special */
UNW_X86_GS, /* special */
UNW_X86_FS, /* special */
UNW_X86_ES, /* special */
UNW_X86_DS, /* special */
UNW_X86_SS, /* special */
UNW_X86_CS, /* special */
UNW_X86_TSS, /* special */
UNW_X86_LDT, /* special */
/* frame info (read-only) */
UNW_X86_CFA,
UNW_X86_XMM0, /* scratch */
UNW_X86_XMM1, /* scratch */
UNW_X86_XMM2, /* scratch */
UNW_X86_XMM3, /* scratch */
UNW_X86_XMM4, /* scratch */
UNW_X86_XMM5, /* scratch */
UNW_X86_XMM6, /* scratch */
UNW_X86_XMM7, /* scratch */
UNW_X86_XMM0, /* scratch */
UNW_X86_XMM1, /* scratch */
UNW_X86_XMM2, /* scratch */
UNW_X86_XMM3, /* scratch */
UNW_X86_XMM4, /* scratch */
UNW_X86_XMM5, /* scratch */
UNW_X86_XMM6, /* scratch */
UNW_X86_XMM7, /* scratch */
UNW_TDEP_LAST_REG = UNW_X86_XMM7,
UNW_TDEP_IP = UNW_X86_EIP,
UNW_TDEP_SP = UNW_X86_ESP,
UNW_TDEP_EH = UNW_X86_EAX
} x86_regnum_t;
}
x86_regnum_t;
#define UNW_TDEP_NUM_EH_REGS 2 /* eax and edx are exception args */
#define UNW_TDEP_NUM_EH_REGS 2 /* eax and edx are exception args */
typedef struct unw_tdep_save_loc {
typedef struct unw_tdep_save_loc
{
/* Additional target-dependent info on a save location. */
char unused;
} unw_tdep_save_loc_t;
}
unw_tdep_save_loc_t;
/* On x86, we can directly use ucontext_t as the unwind context. */
typedef ucontext_t unw_tdep_context_t;
#include "libunwind-dynamic.h"
typedef struct {
typedef struct
{
/* no x86-specific auxiliary proc-info */
char unused;
} unw_tdep_proc_info_t;
}
unw_tdep_proc_info_t;
#include "libunwind-common.h"
#define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext)
extern int unw_tdep_getcontext(unw_tdep_context_t*);
#define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext)
extern int unw_tdep_getcontext (unw_tdep_context_t *);
#define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg)
extern int unw_tdep_is_fpreg(int);
#define unw_tdep_is_fpreg UNW_ARCH_OBJ(is_fpreg)
extern int unw_tdep_is_fpreg (int);
#if defined(__cplusplus) || defined(c_plusplus)
}

View File

@ -50,10 +50,8 @@ elf_w (CD_get_proc_name) (struct UCD_info *ui, unw_addr_space_t as, unw_word_t i
/* segbase: where it is mapped in virtual memory */
/* mapoff: offset in the file */
segbase = cphdr->p_vaddr;
/*mapoff = phdr->p_offset; WRONG! phdr->p_offset is the offset in COREDUMP file */
mapoff = 0;
ret = elf_w (get_proc_name_in_image) (as, &ui->edi.ei, segbase, mapoff, ip, buf, buf_len, offp);
ret = elf_w (get_proc_name_in_image) (as, &ui->edi.ei, segbase, ip, buf, buf_len, offp);
return ret;
}

View File

@ -158,8 +158,7 @@ elf_w (lookup_symbol) (unw_addr_space_t as,
}
static Elf_W (Addr)
elf_w (get_load_offset) (struct elf_image *ei, unsigned long segbase,
unsigned long mapoff)
elf_w (get_load_offset) (struct elf_image *ei, unsigned long segbase)
{
Elf_W (Addr) offset = 0;
Elf_W (Ehdr) *ehdr;
@ -175,7 +174,7 @@ elf_w (get_load_offset) (struct elf_image *ei, unsigned long segbase,
phdr = (Elf_W (Phdr) *) ((char *) ei->image + ehdr->e_phoff);
for (i = 0; i < ehdr->e_phnum; ++i)
if (phdr[i].p_type == PT_LOAD && (phdr[i].p_offset & pagesize_alignment_mask) == mapoff)
if (phdr[i].p_type == PT_LOAD && phdr[i].p_flags & PF_X)
{
offset = segbase - phdr[i].p_vaddr + (phdr[i].p_offset & (~pagesize_alignment_mask));
break;
@ -276,7 +275,6 @@ elf_w (extract_minidebuginfo) (struct elf_image *ei, struct elf_image *mdi)
HIDDEN int
elf_w (get_proc_name_in_image) (unw_addr_space_t as, struct elf_image *ei,
unsigned long segbase,
unsigned long mapoff,
unw_word_t ip,
char *buf, size_t buf_len, unw_word_t *offp)
{
@ -284,7 +282,7 @@ elf_w (get_proc_name_in_image) (unw_addr_space_t as, struct elf_image *ei,
Elf_W (Addr) min_dist = ~(Elf_W (Addr))0;
int ret;
load_offset = elf_w (get_load_offset) (ei, segbase, mapoff);
load_offset = elf_w (get_load_offset) (ei, segbase);
ret = elf_w (lookup_symbol) (as, ip, ei, load_offset, buf, buf_len, &min_dist);
/* If the ELF image has MiniDebugInfo embedded in it, look up the symbol in
@ -328,7 +326,7 @@ elf_w (get_proc_name) (unw_addr_space_t as, pid_t pid, unw_word_t ip,
if (ret < 0)
return ret;
ret = elf_w (get_proc_name_in_image) (as, &ei, segbase, mapoff, ip, buf, buf_len, offp);
ret = elf_w (get_proc_name_in_image) (as, &ei, segbase, ip, buf, buf_len, offp);
munmap (ei.image, ei.size);
ei.image = NULL;

View File

@ -50,7 +50,6 @@ extern int elf_w (get_proc_name) (unw_addr_space_t as,
extern int elf_w (get_proc_name_in_image) (unw_addr_space_t as,
struct elf_image *ei,
unsigned long segbase,
unsigned long mapoff,
unw_word_t ip,
char *buf, size_t buf_len, unw_word_t *offp);