LIBTCCAPI tcc_relocate(s) : REMOVED 2nd argument

removed second argument for tcc_relocate(s). previous
'TCC_RELOCATE_AUTO' is now default and only behavior.

Rationale:
  In the past, the option to compile into memory provided by the
  user was introduced because only one TCCState could exist at a time.

  This is no longer a limitation.  As such it is also possible now to
  keep any number of compiled code snippets around together with their
  state in order to run them as needed.

- Also
  - LIBTCCAPI tcc_get_error_func/opaque() removed
  - tccrun/SELINUX: switch rx/rw mappings such that rx comes first
    (risc64-link.c:relocate_plt() does not like got < plt)
  - tcc_relocate_ex(): free local symbols and obsolete sections
    to reduce memory after tcc_relocate()
This commit is contained in:
grischka
2024-02-07 07:42:56 +01:00
parent a0ab99169e
commit b671fc0594
11 changed files with 224 additions and 184 deletions

View File

@@ -1,4 +1,3 @@
#include <unistd.h>
#include <libtcc.h>
#include <stdlib.h>
#include <stdio.h>
@@ -53,7 +52,7 @@ static int run_callback(const char *src, callback_type callback) {
return -1;
if (tcc_compile_string(s, src) == -1)
return -1;
if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1)
if (tcc_relocate(s) == -1)
return -1;
ptr = tcc_get_symbol(s, "f");

View File

@@ -6,8 +6,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "libtcc.h"
void handle_error(void *opaque, const char *msg)
@@ -59,14 +57,9 @@ int main(int argc, char **argv)
exit(1);
}
assert(tcc_get_error_func(s) == NULL);
assert(tcc_get_error_opaque(s) == NULL);
/* set custom error/warning printer */
tcc_set_error_func(s, stderr, handle_error);
assert(tcc_get_error_func(s) == handle_error);
assert(tcc_get_error_opaque(s) == stderr);
/* if tcclib.h and libtcc1.a are not installed, where can we find them */
for (i = 1; i < argc; ++i) {
char *a = argv[i];
@@ -92,7 +85,7 @@ int main(int argc, char **argv)
tcc_add_symbol(s, "hello", hello);
/* relocate the code */
if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
if (tcc_relocate(s) < 0)
return 1;
/* get entry symbol */

View File

@@ -128,7 +128,7 @@ void *reloc_state(TCCState *s, const char *entry)
{
void *func;
tcc_add_symbol(s, "add", add);
if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) {
if (tcc_relocate(s) < 0) {
fprintf(stderr, __FILE__ ": could not relocate tcc state.\n");
return NULL;
}