Skip to content

Commit

Permalink
Limit exported symbols (#35)
Browse files Browse the repository at this point in the history
* build: Set soname on Linux

The merge of MR dropped `else` which made the soname setting
ineffective on Linux.

* Limit exported symbols

This greatly reduces the number of exported symbols by limiting the
namespace of exported symbols to {varnam,varray,vm}_ thus avoiding the
export of all the `_cg` symbols from go.

Before:

$ readelf -s /tmp/a/usr/lib/libgovarnam.so.1.9.0  | grep -v " UND " | wc -l
248

After:

$ readelf -s /usr/lib/libgovarnam.so.1.9.0  | grep -v " UND " | wc -l
52

With this we can make sure applications don't link against accidentally
exported symbols and break on library upgrades without us being able to
notice. It also allows us to notice when symbols go missing and we hence
need to bump the ABI version.
agx authored Sep 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0890d8c commit 436d006
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -17,11 +17,13 @@ UNAME := $(shell uname)
SED := sed -i
LIB_NAME := libgovarnam.so
SO_NAME := $(shell (echo $(VERSION) | cut -d. -f1))
CURDIR := $(shell pwd)

ifeq ($(UNAME), Darwin)
SED := sed -i ""
LIB_NAME = libgovarnam.dylib
EXT_LDFLAGS = -extldflags -Wl,-soname,$(LIB_NAME).$(SO_NAME)
else
EXT_LDFLAGS = -extldflags "-Wl,-soname,$(LIB_NAME).$(SO_NAME),--version-script,$(CURDIR)/govarnam.syms"
endif

VERSION_STAMP_LDFLAGS := -X 'github.com/varnamproject/govarnam/govarnam.BuildString=${BUILDSTR}' -X 'github.com/varnamproject/govarnam/govarnam.VersionString=${VERSION}' $(EXT_LDFLAGS)
9 changes: 9 additions & 0 deletions govarnam.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
global:
varnam_*;
varray_*;
vm_*;
local:
*;
};

0 comments on commit 436d006

Please sign in to comment.