pgaskin / NickelMenu

The easiest way to launch scripts, change settings, and run actions on Kobo e-readers.
https://pgaskin.net/NickelMenu
MIT License
556 stars 28 forks source link

Hide (nearly) all symbols by default #40

Closed NiLuJe closed 4 years ago

NiLuJe commented 4 years ago

Brought on by https://github.com/geek1011/kobo-plugin-experiments/issues/9#issuecomment-642324579, even if that doesn't really answer everything ^^.

NiLuJe commented 4 years ago

@geek1011: I once again fat-fingered a branch without a namespace (and it's a shell alias, so it pushes -_-"), my bad ;/.

pgaskin commented 4 years ago

I'd rather hide each symbol individually using the visibility attribute (put it into a #define NM_PRIVATE or something like that), especially since at least for the moment, other mods will use dlhook directly from a NM git submodule.

Also, regarding stripping, I'd personally prefer to avoid it for now by default unless absolutely necessary since it's useful to have the symbol table when debugging.

NiLuJe commented 4 years ago

I still have mysterious extra Qt crap in the symbol table by doing it this way:

--- symbols-hidden      2020-06-11 19:47:27.351264858 +0200
+++ symbols-not-hidden  2020-06-11 20:14:37.692246575 +0200
@@ -92,6 +92,10 @@ _ZN14QImageIOPluginC2EP7Q
 _ZN14QImageIOPluginD2Ev
 _ZN15QtSharedPointer20Ext
 _ZN16QCoreApplication9tra
+_ZN5QListI7QStringE18deta
+_ZN5QListI7QStringE6appen
+_ZN5QListI7QStringED1Ev
+_ZN5QListI7QStringED2Ev
 _ZN7QAction16staticMetaOb
 _ZN7QAction9triggeredEb
 _ZN7QObject10childEventEP
@@ -113,6 +117,14 @@ _ZN7QStringD1Ev
 _ZN7QStringD2Ev
 _ZN7QWidget6updateEv
 _ZN7QWidget9addActionEP7Q
+_ZN8NMPlugin11qt_metacall
+_ZN8NMPlugin11qt_metacast
+_ZN8NMPlugin16staticMetaO
+_ZN8NMPluginD0Ev
+_ZN8NMPluginD1Ev
+_ZN8NMPluginD2Ev
+_ZN8QPointerI7QObjectED1E
+_ZN8QPointerI7QObjectED2E
 _ZN8QProcess13startDetach
 _ZN8QProcess15waitForFini
 _ZN8QProcess19setWorkingD
@@ -127,9 +139,13 @@ _ZN9QListData11detach_gro
 _ZN9QListData11shared_nul
 _ZN9QListData6appendEv
 _ZN9QListData7disposeEPNS
+_ZN9QtPrivate18QFunctorSl
 _ZNK11QObjectData17dynami
 _ZNK7QString11toLocal8Bit
 _ZNK7QString4leftEi
+_ZNK8NMPlugin10metaObject
+_ZNK8NMPlugin12capabiliti
+_ZNK8NMPlugin6createEP9QI
 _ZNK8QProcess10exitStatus
 _ZNK8QProcess5errorEv
 _ZNK8QProcess8exitCodeEv
@@ -137,5 +153,9 @@ _ZNK8QVariant6toBoolEv
 _Znwj@GLIBCXX_3.4
 _ZSt25__throw_bad_functio@GLIBCXX_3.4.14
 _ZTI14QImageIOPlugin
+_ZTI8NMPlugin
+_ZTS8NMPlugin
+_ZTV8NMPlugin
 _ZTVN10__cxxabiv117__clas@CXXABI_1.3
 _ZTVN10__cxxabiv120__si_c@CXXABI_1.3
+_ZZN9QtPrivate15Connectio

(Plus the NMPlugin class, which I can also hide, actually?).

pgaskin commented 4 years ago

I'll look at the changes in more detail a bit later today. One random thought: it doesn't matter if there are conflicting symbols when loading as a plugin (or dlopen), only when using it with LD_PRELOAD, so we could maybe just discontinue LD_PRELOAD support?

NiLuJe commented 4 years ago

Hmm, probably the crap from the Q_OBJECT macro in the Plugin's class ;).

Does hiding the class itself make sense, @geek1011?

(I mean, it does sound a bit stupid, but then it certainly worked when built w/ -fvisibility=hidden ^^).

diff --git a/src/qtplugin.h b/src/qtplugin.h
index 113a7aa..afc82c1 100644
--- a/src/qtplugin.h
+++ b/src/qtplugin.h
@@ -3,10 +3,12 @@
 #include <QObject>
 #include <QtPlugin>

+#include "visibility.h"
+
 // we make it a fake image plugin so we can have Qt automatically load it
 // without needing extra configuration (e.g. LD_PRELOAD, -plugin arg, etc).

-class NMPlugin : public QImageIOPlugin {
+class NM_PRIVATE NMPlugin : public QImageIOPlugin {
     Q_OBJECT
     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface")
 public:

That leaves:

--- symbols-hidden      2020-06-11 19:47:27.351264858 +0200
+++ symbols-not-hidden  2020-06-11 20:25:27.167239292 +0200
@@ -92,6 +92,10 @@ _ZN14QImageIOPluginC2EP7Q
 _ZN14QImageIOPluginD2Ev
 _ZN15QtSharedPointer20Ext
 _ZN16QCoreApplication9tra
+_ZN5QListI7QStringE18deta
+_ZN5QListI7QStringE6appen
+_ZN5QListI7QStringED1Ev
+_ZN5QListI7QStringED2Ev
 _ZN7QAction16staticMetaOb
 _ZN7QAction9triggeredEb
 _ZN7QObject10childEventEP
@@ -113,6 +117,8 @@ _ZN7QStringD1Ev
 _ZN7QStringD2Ev
 _ZN7QWidget6updateEv
 _ZN7QWidget9addActionEP7Q
+_ZN8QPointerI7QObjectED1E
+_ZN8QPointerI7QObjectED2E
 _ZN8QProcess13startDetach
 _ZN8QProcess15waitForFini
 _ZN8QProcess19setWorkingD
@@ -127,6 +133,7 @@ _ZN9QListData11detach_gro
 _ZN9QListData11shared_nul
 _ZN9QListData6appendEv
 _ZN9QListData7disposeEPNS
+_ZN9QtPrivate18QFunctorSl
 _ZNK11QObjectData17dynami
 _ZNK7QString11toLocal8Bit
 _ZNK7QString4leftEi
@@ -139,3 +146,4 @@ _ZSt25__throw_bad_functio@GLIBCXX_3.4.14
 _ZTI14QImageIOPlugin
 _ZTVN10__cxxabiv117__clas@CXXABI_1.3
 _ZTVN10__cxxabiv120__si_c@CXXABI_1.3
+_ZZN9QtPrivate15Connectio
pgaskin commented 4 years ago

Does hiding the class itself make sense, @geek1011?

I'm not sure. Have you tried actually running the plugin to see if it works that way?

NiLuJe commented 4 years ago

See my latest edit ;).

I agree that it "feels" weird, but it worked w/ -fvisibility=hidden.

In any case, that doesn't take care of the macro stuff anyway, so, eh, probably ought to leave it alone ;).

pgaskin commented 4 years ago

I wonder if doing a combination would be the best option:

Thoughts?

NiLuJe commented 4 years ago

I wonder if doing a combination would be the best option:

* `-fvisibility=hidden` to hide most stuff in general.

That'll make everything not explicitly annotated hidden, which works for me ;).

* Explicitly make the hook visible.

Done already, so, we're safe.

* Explicitly make the dlhook and failsafe stuff hidden to allow using as-is in other mods.

Also already done.

* Leave `NMPlugin` as-is (if it's loaded with LD_PRELOAD, conflicts won't matter since this is only used by Qt for plugin metadata).

I'm inclined to agree.

Everything in there will get hidden by -fvisibility=hidden anyway, and that certainly worked fine on my end (haven't tested PRELOAD, though) ;).

* Don't strip stuff by default, since it's useful for debugging and troubleshooting.

Already done ;).

Thoughts?

shermp commented 4 years ago

Ummm... wasn't expecting this when I posted my comment! Should certainly help though,