1
0

Hide (nearly) all symbols by default (#40)

https://github.com/geek1011/kobo-plugin-experiments/issues/9#issuecomment-642324579
This commit is contained in:
NiLuJe
2020-06-23 09:37:00 +02:00
committed by GitHub
parent ff434c9669
commit d0d169769b
6 changed files with 23 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ MOC = moc
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
STRIP = $(CROSS_COMPILE)strip
DESTDIR =
@@ -74,6 +75,9 @@ export GITIGNORE_HEAD
all: src/libnm.so
strip: src/libnm.so
$(STRIP) --strip-unneeded $(CURDIR)/src/libnm.so
clean:
rm -f $(GENERATED)
@@ -90,11 +94,11 @@ install:
koboroot:
tar cvzf KoboRoot.tgz --show-transformed --owner=root --group=root --mode="u=rwX,go=rX" --transform="s,src/libnm.so,./usr/local/Kobo/imageformats/libnm.so," --transform="s,res/doc,./mnt/onboard/.adds/nm/doc," src/libnm.so res/doc
.PHONY: all clean gitignore install koboroot
.PHONY: all strip clean gitignore install koboroot
override GENERATED += KoboRoot.tgz
src/libnm.so: override CFLAGS += $(PTHREAD_CFLAGS) -fPIC
src/libnm.so: override CXXFLAGS += $(PTHREAD_CFLAGS) $(QT5CORE_CFLAGS) $(QT5WIDGETS_CFLAGS) -fPIC
src/libnm.so: override CFLAGS += $(PTHREAD_CFLAGS) -fvisibility=hidden -fPIC
src/libnm.so: override CXXFLAGS += $(PTHREAD_CFLAGS) $(QT5CORE_CFLAGS) $(QT5WIDGETS_CFLAGS) -fvisibility=hidden -fvisibility-inlines-hidden -fPIC
src/libnm.so: override LDFLAGS += $(PTHREAD_LIBS) $(QT5CORE_LIBS) $(QT5WIDGETS_LIBS) -ldl -Wl,-soname,libnm.so
src/libnm.so: src/qtplugin.o src/init.o src/config.o src/dlhook.o src/failsafe.o src/menu.o src/kfmon.o src/action.o src/action_c.o src/action_cc.o src/generator.o src/generator_c.o

View File

@@ -4,13 +4,15 @@
extern "C" {
#endif
#include "util.h"
// nm_dlhook takes a lib handle from dlopen and redirects the specified symbol
// to another, returning a pointer to the original one. Only calls from within
// that library itself are affected (because it replaces that library's GOT). If
// an error occurs, NULL is returned and if err is a valid pointer, it is set to
// a malloc'd string describing it. This function requires glibc and Linux. It
// should work on any architecture, and it should be resilient to most errors.
void *nm_dlhook(void *handle, const char *symname, void *target, char **err_out);
NM_PRIVATE void *nm_dlhook(void *handle, const char *symname, void *target, char **err_out);
#ifdef __cplusplus
}

View File

@@ -4,6 +4,8 @@
extern "C" {
#endif
#include "util.h"
// nm_failsafe_t is a failsafe mechanism for injected shared libraries. It
// works by moving it to a temporary file (so it won't get loaded the next time)
// and dlopening itself (to prevent it from being unloaded if it is dlclose'd by
@@ -12,16 +14,16 @@ extern "C" {
typedef struct nm_failsafe_t nm_failsafe_t;
// nm_failsafe_create allocates and arms a failsafe mechanism for the currently
// dlopen'd or LD_PRELOAD'd library.
nm_failsafe_t *nm_failsafe_create(char **err_out);
// dlopen'd or LD_PRELOAD'd library.
NM_PRIVATE nm_failsafe_t *nm_failsafe_create(char **err_out);
// nm_failsafe_destroy starts a pthread which disarms and frees the failsafe
// after a delay. The nm_failsafe_t must not be used afterwards.
void nm_failsafe_destroy(nm_failsafe_t *fs, int delay);
NM_PRIVATE void nm_failsafe_destroy(nm_failsafe_t *fs, int delay);
// nm_failsafe_uninstall uninstalls the lib. The nm_failsafe_t must not be
// used afterwards.
void nm_failsafe_uninstall(nm_failsafe_t *fs);
NM_PRIVATE void nm_failsafe_uninstall(nm_failsafe_t *fs);
#ifdef __cplusplus
}

View File

@@ -113,7 +113,7 @@ void nm_menu_item_do(nm_menu_item_t *it);
// _nm_menu_inject handles the QMenu::aboutToShow signal and injects menu items.
void _nm_menu_inject(void *nmc, QMenu *menu, nm_menu_location_t loc, int at);
extern "C" MenuTextItem* _nm_menu_hook(void* _this, QMenu* menu, QString const& label, bool checkable, bool checked, QString const& thingy) {
extern "C" NM_PUBLIC MenuTextItem* _nm_menu_hook(void* _this, QMenu* menu, QString const& label, bool checkable, bool checked, QString const& thingy) {
NM_LOG("AbstractNickelMenuController::createMenuTextItem(%p, `%s`, %d, %d, `%s`)", menu, qPrintable(label), checkable, checked, qPrintable(thingy));
QString trmm = QCoreApplication::translate("StatusBarMenuController", "Settings");

View File

@@ -35,4 +35,4 @@ int nm_menu_hook(void *libnickel, char **err_out);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@@ -22,9 +22,13 @@ extern "C" {
#define NM_LOG_NAME "NickelMenu"
#endif
// Symbol visibility
#define NM_PUBLIC __attribute__((visibility("default")))
#define NM_PRIVATE __attribute__((visibility("hidden")))
// strtrim trims ASCII whitespace in-place (i.e. don't give it a string literal)
// from the left/right of the string.
inline char *strtrim(char *s){
inline char *strtrim(char *s) {
if (!s) return NULL;
char *a = s, *b = s + strlen(s);
for (; a < b && isspace((unsigned char)(*a)); a++);