From b7786ebd30816e9065e45cf19ce2d2a57f4b38a1 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 19 Jan 2011 11:59:03 +0000 Subject: [PATCH] find_undefined_symbol_add_on(): Resolve non-weak symbols defined in the add-on to themselves. This works around the problem that those symbols could be resolved to symbols in the application, which is usually undesired. Weak symbols have the same problem, but the the runtime loader cannot decide which should be resolved locally and which mustn't. The root issue is that BeOS style add-ons simply cannot be supported by a standard-complying ELF loader. Affects gcc 4 only, since with gcc 2 we link everything symbolically. The best solution for the time being would be to build gcc 4 add-ons with default hidden visibility, exporting only the symbols that should be visible. Related ticket: #7114 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40248 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../runtime_loader/elf_symbol_lookup.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/system/runtime_loader/elf_symbol_lookup.cpp b/src/system/runtime_loader/elf_symbol_lookup.cpp index 5ccd554df8..b2f6d16a04 100644 --- a/src/system/runtime_loader/elf_symbol_lookup.cpp +++ b/src/system/runtime_loader/elf_symbol_lookup.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * @@ -401,6 +401,24 @@ find_undefined_symbol_add_on(image_t* rootImage, image_t* image, // library symbol references to symbol definitions in the add-on, as // libraries can be shared between different add-ons and we must not // introduce connections between add-ons. + + // For the add-on image itself resolve non-weak symbols defined in the + // add-on to themselves. This makes the symbol resolution order inconsistent + // for those symbols, but avoids clashes of global symbols defined in the + // add-on with symbols defined e.g. in the application. There's really the + // same problem for weak symbols, but we don't have any way to discriminate + // weak symbols that must be resolved globally from those that should be + // resolved within the add-on. + if (rootImage == image) { + if (Elf32_Sym* symbol = lookupInfo.requestingSymbol) { + if (symbol->st_shndx != SHN_UNDEF + && (ELF32_ST_BIND(symbol->st_info) == STB_GLOBAL)) { + *_foundInImage = image; + return symbol; + } + } + } + image_t* candidateImage = NULL; Elf32_Sym* candidateSymbol = NULL;