mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added some more PIE/PIC code. Not quite correct yet unfortunately.
This commit is contained in:
@@ -277,14 +277,29 @@ static void parse_option(void)
|
||||
build_options.feature.reg_struct_return = true;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fpie"))
|
||||
{
|
||||
build_options.pie = PIE_SMALL;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fPIE"))
|
||||
{
|
||||
build_options.pie = PIE_BIG;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fno-pie"))
|
||||
{
|
||||
build_options.pie = PIE_NONE;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fpic"))
|
||||
{
|
||||
build_options.pic = SMALL_PIC_USE;
|
||||
build_options.pic = PIC_SMALL;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fPIC"))
|
||||
{
|
||||
build_options.pic = BIG_PIC_USE;
|
||||
build_options.pic = PIC_BIG;
|
||||
return;
|
||||
}
|
||||
if (match_shortopt("fno-pic"))
|
||||
|
||||
@@ -88,14 +88,24 @@ typedef enum
|
||||
SIZE_OPTIMIZATION_TINY = 2, // -Oz
|
||||
} SizeOptimizationLevel;
|
||||
|
||||
// Values correspond to LLVM values.
|
||||
typedef enum
|
||||
{
|
||||
PIC_DEFAULT,
|
||||
PIC_NONE,
|
||||
BIG_PIC_USE,
|
||||
SMALL_PIC_USE,
|
||||
PIC_DEFAULT = -1,
|
||||
PIC_NONE = 0,
|
||||
PIC_SMALL = 1,
|
||||
PIC_BIG = 2,
|
||||
} PicGeneration;
|
||||
|
||||
// Values correspond to LLVM values
|
||||
typedef enum
|
||||
{
|
||||
PIE_NONE = -1,
|
||||
PIE_DEFAULT = 0,
|
||||
PIE_SMALL = 1,
|
||||
PIE_BIG = 2,
|
||||
} PieGeneration;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DEBUG_INFO_NONE,
|
||||
@@ -137,6 +147,7 @@ typedef struct
|
||||
const char* cpu;
|
||||
const char* target_triple;
|
||||
PicGeneration pic;
|
||||
PieGeneration pie;
|
||||
bool generate_lib;
|
||||
struct
|
||||
{
|
||||
|
||||
@@ -13,6 +13,20 @@ void gencontext_begin_module(GenContext *context)
|
||||
context->module = LLVMModuleCreateWithNameInContext(mangled_module_name, context->context);
|
||||
LLVMSetModuleDataLayout(context->module, target_data_layout());
|
||||
LLVMSetSourceFileName(context->module, full_path, strlen(context->ast_context->file->full_path));
|
||||
LLVMTypeRef options_type = LLVMInt8TypeInContext(context->context);
|
||||
|
||||
if (build_options.pic == PIC_BIG || build_options.pic == PIC_SMALL)
|
||||
{
|
||||
static const char *pic_level = "PIC Level";
|
||||
LLVMMetadataRef setting = LLVMValueAsMetadata(LLVMConstInt(options_type, build_options.pic, false));
|
||||
LLVMAddModuleFlag(context->module, LLVMModuleFlagBehaviorOverride, pic_level, strlen(pic_level), setting);
|
||||
}
|
||||
if (build_options.pie == PIE_BIG || build_options.pie == PIE_SMALL)
|
||||
{
|
||||
static const char *pie_level = "PIE Level";
|
||||
LLVMMetadataRef setting = LLVMValueAsMetadata(LLVMConstInt(options_type, build_options.pie, false));
|
||||
LLVMAddModuleFlag(context->module, LLVMModuleFlagBehaviorOverride, pie_level, strlen(pie_level), setting);
|
||||
}
|
||||
|
||||
LLVMSetTarget(context->module, build_target.target_triple);
|
||||
if (build_options.debug_info != DEBUG_INFO_NONE)
|
||||
|
||||
@@ -419,7 +419,7 @@ void target_setup(void)
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
if (build_options.pic == BIG_PIC_USE || build_options.pic == SMALL_PIC_USE || build_options.generate_lib)
|
||||
if (build_options.pic == PIC_BIG || build_options.pic == PIC_SMALL || build_options.generate_lib)
|
||||
{
|
||||
reloc_mode = LLVMRelocPIC;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user