thread-local storage model of a variable:
* :func:`gcc_jit_lvalue_set_tls_model`
+
+.. _LIBGCCJIT_ABI_18:
+
+``LIBGCCJIT_ABI_18``
+-----------------------
+``LIBGCCJIT_ABI_18`` covers the addition of an API entrypoint to set the link
+section of a variable:
+
+ * :func:`gcc_jit_lvalue_set_link_section`
#ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_tls_model
+.. function:: void
+ gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
+ const char *section_name)
+
+ Set the link section of a variable.
+ The parameter ``section_name`` must be non-NULL and must contain the
+ leading dot. Analogous to:
+
+ .. code-block:: c
+
+ int variable __attribute__((section(".section")));
+
+ in C.
+
+ This entrypoint was added in :ref:`LIBGCCJIT_ABI_18`; you can test for
+ its presence using
+
+ .. code-block:: c
+
+ #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section
+
Global variables
****************
set_decl_tls_model (as_tree (), tls_model);
}
+ void
+ set_link_section (const char* name)
+ {
+ set_decl_section_name (as_tree (), name);
+ }
+
private:
bool mark_addressable (location *loc);
};
m_tls_model = model;
}
+void recording::lvalue::set_link_section (const char *name)
+{
+ m_link_section = new_string (name);
+}
+
/* The implementation of class gcc::jit::recording::param. */
/* Implementation of pure virtual hook recording::memento::replay_into
void
recording::global::replay_into (replayer *r)
{
- playback::lvalue *global = m_initializer
- ? r->new_global_initialized (playback_location (r, m_loc),
+ playback::lvalue *global = m_initializer
+ ? r->new_global_initialized (playback_location (r, m_loc),
m_kind,
m_type->playback_type (),
m_type->dereference ()->get_size (),
/ m_type->dereference ()->get_size (),
m_initializer,
playback_string (m_name))
- : r->new_global (playback_location (r, m_loc),
+ : r->new_global (playback_location (r, m_loc),
m_kind,
m_type->playback_type (),
playback_string (m_name));
+
if (m_tls_model != GCC_JIT_TLS_MODEL_NONE)
global->set_tls_model (recording::tls_models[m_tls_model]);
+ if (m_link_section != NULL)
+ global->set_link_section (m_link_section->c_str ());
+
set_playback_obj (global);
}
id,
tls_model_enum_strings[m_tls_model]);
+ if (m_link_section != NULL)
+ r.write (" gcc_jit_lvalue_set_link_section (%s, /* gcc_jit_lvalue *lvalue */\n"
+ " \"%s\"); /* */\n",
+ id,
+ m_link_section->c_str ());
+
if (m_initializer)
switch (m_type->dereference ()->get_size ())
{
location *loc,
type *type_)
: rvalue (ctxt, loc, type_),
- m_tls_model (GCC_JIT_TLS_MODEL_NONE)
+ m_tls_model (GCC_JIT_TLS_MODEL_NONE),
+ m_link_section (NULL)
{}
playback::lvalue *
virtual const char *access_as_lvalue (reproducer &r);
virtual bool is_global () const { return false; }
void set_tls_model (enum gcc_jit_tls_model model);
+ void set_link_section (const char *name);
protected:
enum gcc_jit_tls_model m_tls_model;
+ string *m_link_section;
};
class param : public lvalue
lvalue->set_tls_model (model);
}
+/* Public entrypoint. See description in libgccjit.h.
+
+ After error-checking, the real work is done by the
+ gcc::jit::recording::lvalue::set_link_section method in jit-recording.c. */
+
+void
+gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
+ const char *section_name)
+{
+ RETURN_IF_FAIL (section_name, NULL, NULL, "NULL section_name");
+ lvalue->set_link_section (section_name);
+}
+
/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,
enum gcc_jit_tls_model model);
+#define LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section
+
+/* Set the link section of a global variable; analogous to:
+ __attribute__((section(".section_name")))
+ in C.
+
+ This API entrypoint was added in LIBGCCJIT_ABI_18; you can test for its
+ presence using
+ #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_set_link_section
+*/
+extern void
+gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
+ const char *section_name);
+
extern gcc_jit_lvalue *
gcc_jit_function_new_local (gcc_jit_function *func,
gcc_jit_location *loc,
global:
gcc_jit_lvalue_set_tls_model;
} LIBGCCJIT_ABI_16;
+
+LIBGCCJIT_ABI_18 {
+ global:
+ gcc_jit_lvalue_set_link_section;
+} LIBGCCJIT_ABI_17;
#undef create_code
#undef verify_code
+/* test-link-section-assembler.c: This can't be in the testcases array as it
+ doesn't have a verify_code implementation. */
+
/* test-linked-list.c */
#define create_code create_code_linked_list
#define verify_code verify_code_linked_list
jit-run-executable ${executable_from_asm} ${dg-output-text}
}
+# Assuming that a .s file has been written out named
+# OUTPUT_FILENAME, check that the argument matches the
+# output file.
+# For use by the test-link-section-assembler.c testcase.
+proc jit-verify-assembler-output { args } {
+ verbose "jit-verify-assembler: $args"
+
+ set dg-output-text [lindex $args 0]
+ verbose "dg-output-text: ${dg-output-text}"
+
+ upvar 2 name name
+ verbose "name: $name"
+
+ upvar 2 prog prog
+ verbose "prog: $prog"
+ set asm_filename [jit-get-output-filename $prog]
+ verbose " asm_filename: ${asm_filename}"
+
+ # Read the assembly file.
+ set f [open $asm_filename r]
+ set content [read $f]
+ close $f
+
+ # Verify that the assembly matches the regex.
+ if { ![regexp ${dg-output-text} $content] } {
+ fail "${asm_filename} output pattern test, is ${content}, should match ${dg-output-text}"
+ verbose "Failed test for output pattern ${dg-output-text}" 3
+ } else {
+ pass "${asm_filename} output pattern test, ${dg-output-text}"
+ verbose "Passed test for output pattern ${dg-output-text}" 3
+ }
+
+}
# Assuming that a .o file has been written out named
# OUTPUT_FILENAME, invoke the driver to try to turn it into
# an executable, and try to run the result.
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#define TEST_COMPILING_TO_FILE
+#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
+#define OUTPUT_FILENAME "output-of-test-link-section-assembler.c.s"
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Let's try to inject the equivalent of:
+ int foo __attribute__((section(".section")));
+ */
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_lvalue *foo =
+ gcc_jit_context_new_global (
+ ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo");
+ gcc_jit_lvalue_set_link_section(foo, ".my_section");
+
+ gcc_jit_function *func_main =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ int_type,
+ "main",
+ 0, NULL,
+ 0);
+ gcc_jit_rvalue *zero = gcc_jit_context_zero (ctxt, int_type);
+ gcc_jit_block *block = gcc_jit_function_new_block (func_main, NULL);
+ gcc_jit_block_end_with_return (block, NULL, zero);
+}
+
+/* { dg-final { jit-verify-output-file-was-created "" } } */
+/* { dg-final { jit-verify-assembler-output ".section .my_section" } } */