Opened 6 years ago

Last modified 2 years ago

#14531 new bug

dlopen: program symbols override the one used by library

Reported by: leorize Owned by: nobody
Priority: high Milestone: Unscheduled
Component: Build System Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

The snippet attached below describe this problem.

How to run:

$ gcc -o dl dl.c
$ gcc -DLIBRARY -shared -o dl.so dl.c
$ LIBRARY_PATH="$PWD:$LIBRARY_PATH" ./dl

Expected:

from library

Got:

from program

The snippet has been tested on Linux, OpenBSD, FreeBSD and so far only Haiku exhibit this behavior.

Attachments (1)

dl.c (504 bytes ) - added by leorize 6 years ago.

Download all attachments as: .zip

Change History (12)

by leorize, 6 years ago

Attachment: dl.c added

comment:1 by leorize, 6 years ago

As a walkaround, the binary can be compiled with -fvisibility=hidden to get the desired behavior

comment:2 by leorize, 6 years ago

It's found that if the binary was compiled with -pie, we can get the desired behavior.

comment:3 by korli, 6 years ago

Priority: highnormal

comment:4 by waddlesplash, 6 years ago

Component: System/POSIXSystem/runtime_loader
Priority: normalhigh

You don't even need dlopen, this will happen with just regular shared libraries; and the symbols can even be "semi-hidden" as they are when a static library is linked into a regular library.

So this is a higher-priority issue, then.

comment:5 by jackburton, 6 years ago

Does this happen also on x64 or only or x86/gcc2 ?

comment:6 by waddlesplash, 6 years ago

Actually it happens on GCC7 only, GCC2 is unaffected. Further testing finds that this affects regular library loads, not just dlopen ones. E.g. a library can have a local function called calloc and then it will override the one from libroot. I'll attach a test binary later.

Adding -Xlinker -Bsymbolic to GCC7 linkspec fixes the issue. Why aren't we doing that already?

comment:7 by leorize, 6 years ago

It's a separate issue. Using -Bsymbolic does not solve the problem for dlopen(), only for linked libraries.

The linkspec of gcc2 is vastly different from gcc7, and I still haven't know why. I'll push a PR to adjust gcc7 linkspec later.

comment:8 by korli, 6 years ago

When using --export-dynamic Linux behaves the same as Haiku.

This isn't a bug in runtime_loader. Can we close this bug?

comment:9 by leorize, 6 years ago

On Linux and other *nix as well as Windows, we'd have to ask the linker to get this behavior. But on Haiku this is forced and can't be avoided without ill effects (crashing upon the use of TLS (haven't recheck since @waddlesplash fix), or have all symbols hidden). So I'd say we should not close this bug.

comment:10 by korli, 6 years ago

Component: System/runtime_loader- General

comment:11 by waddlesplash, 2 years ago

Component: - GeneralBuild System
Note: See TracTickets for help on using tickets.