Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker symbol overriding #217

Open
ghost opened this issue Jan 24, 2018 · 2 comments
Open

Linker symbol overriding #217

ghost opened this issue Jan 24, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 24, 2018

The shared library exposes commonly used symbols that can be accidentally overridden by the linker. Here's an example:

#include <lwan/lwan.h>

struct config {
	int dummy;
};

struct config *config_open(const char *path)
{
	// TODO: To be implemented.
	return NULL;
}

int main(void)
{
	struct lwan lwan;
	lwan_init(&lwan);
}

After successfully compiling this code, the output of the executable will always be:

27630 lwan-job.c:96 lwan_job_thread_init() Initializing low priority job thread.
27630 lwan-tables.c:40 lwan_tables_init() Uncompressing MIME type table.
27630 lwan.c:370 setup_from_config() Loading configuration file: main.conf.
27630 lwan.c:532 lwan_init_with_config() Could not read config file: (null).

Lwan will always fail to read the configuration file because the linker has replaced its implementation of config_open with this one.

Other seemingly harmless names include str_find, parse_int, list_check and hash_add. Names like that are common in application code. Users have to either mark their functions static or use prefixes to avoid naming conflicts.

Are there any plans to add the lwan_ prefix or to not expose these symbols from the library?

@lpereira
Copy link
Owner

lpereira commented Jan 25, 2018

This kind of plumbing work is something I've been postponing for a while. (There are plenty of other things to clean up in the source code that have a similar nature; the header files for instance are a mess.)

For things that are lwan-specific, like the configuration file parser, yes, adding a prefix would help. For things that are implementation details, such as the linked list, string pattern matcher, and hash table functions -- I guess the best solution would be to just use a linker version script in the ELF targets.

@lpereira
Copy link
Owner

e2b3ce2 added a version script. Only some symbols are being exposed right now. Next on the list is to determine what other symbols without the lwan_ prefix should be exposed, rename them so that they have the proper prefix, and update the version script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant