Skip to content

Commit

Permalink
Limit exported symbols
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agx committed Sep 20, 2023
1 parent a42090f commit 928ff64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +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
else
EXT_LDFLAGS = -extldflags -Wl,-soname,$(LIB_NAME).$(SO_NAME)
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)
Expand Down
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 928ff64

Please sign in to comment.