TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Dynamic Linking Best Practices

134 点作者 begriffs将近 4 年前

8 条评论

pjmlp将近 4 年前
&gt; The design typically used nowadays for dynamic linking (in BSD, MacOS, and Linux) came from SunOS in 1988. The paper Shared Libraries in SunOS neatly explains the goals, design, and implementation.<p>Aix shared libraries follow a model similar to Windows, with export files.<p><a href="https:&#x2F;&#x2F;www.ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.2?topic=memory-creating-shared-library" rel="nofollow">https:&#x2F;&#x2F;www.ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.2?topic=memory-creating-sh...</a><p><a href="https:&#x2F;&#x2F;www.ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.2?topic=formats-xcoff-object-file-format" rel="nofollow">https:&#x2F;&#x2F;www.ibm.com&#x2F;docs&#x2F;en&#x2F;aix&#x2F;7.2?topic=formats-xcoff-obje...</a>
secondcoming将近 4 年前
Compiling a shared lib means adding &#x27;fpic&#x27;, which can mean poor codegen if you don&#x27;t handle your symbol visibility well. By default symbols are globally visible and the compiler must assume that at runtime you may do an LD_PRELOAD in order to hook into some functions, and to do that the functions need to be called indirectly rather than directly.<p>At the very least, add &#x27;-fvisibility-inlines-hidden&#x27;.
评论 #27730934 未加载
marco_craveiro将近 4 年前
Very interesting. There was also the old Drepper paper, which was very good but this seems more accessible. [1]<p>[1] <a href="https:&#x2F;&#x2F;akkadia.org&#x2F;drepper&#x2F;dsohowto.pdf" rel="nofollow">https:&#x2F;&#x2F;akkadia.org&#x2F;drepper&#x2F;dsohowto.pdf</a>
janci将近 4 年前
How this compares to Windows? IIRC it is all handled by the executable itself? The kernel32.dll is loaded at known address and it has LoadLibrary function to get a handle of DLL and GetProcAddress that resolves a function name to a function pointer. It loads DLLs from the working directory or system directories. No versioning. (But there are some compatibility tricks to provide correct version of the library even when the dll name does not change)
评论 #27735169 未加载
评论 #27734179 未加载
lgg将近 4 年前
It is good article, but I wish it discussed the differences in dynamic symbol resolution, which is often a source of subtle compatibility issues when porting between POSIX OSes.<p>Linux uses a flat namespace for linking, where each bind lists the symbol name, and then at runtime ld.so searches for that symbol based on the library search order.<p>macOS uses a two level namespace for linking, where each bind lists both the symbol name and the installname of the library that provides the symbol. This means at runtime the dynamic linker does not need use a library search path. This has a number of performance and binary compatibility benefits, though it can make building software a bit more complex.<p>Solaris uses a flat namespace, but retrofitted two levelnamespace semantics via Direct Binding[1][2]. I am not sure how pervasively they are used.<p>I know there were some efforts to port Solaris Direct Binding support to Linux maybe 15 years ago[3][4], but it is a very hard change to make without breaking bin and source compatibility for projects that depend on insert libraries in the search path for partial refinements via interposing symbols.<p>1: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Direct_binding" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Direct_binding</a> 2: <a href="http:&#x2F;&#x2F;www.linker-aliens.org&#x2F;blogs&#x2F;ali&#x2F;entry&#x2F;the_cost_of_elf_symbol&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.linker-aliens.org&#x2F;blogs&#x2F;ali&#x2F;entry&#x2F;the_cost_of_elf...</a> 3: <a href="https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;192624&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;192624&#x2F;</a> 4: <a href="https:&#x2F;&#x2F;bugs.gentoo.org&#x2F;114008" rel="nofollow">https:&#x2F;&#x2F;bugs.gentoo.org&#x2F;114008</a>
Miiko将近 4 年前
Good coverage of dynamic linking, but for this part:<p>&gt; To solve these problems, I suggest bundling all development (linking) library files together into a different directory structure per version.<p>Isn&#x27;t it almost exactly what&#x27;s called &quot;framework&quot; on macOS (author&#x27;s proposed structure is different, but the idea looks the same)?
rualca将近 4 年前
This article is a superb treasure trove of experience on dynamic linking. Thanks for sharing this gem.
Digitalis33将近 4 年前
As someone who&#x27;s just now diving into low-level programming on unix, this article is just what I needed.<p>Saving this for future reference.