Skip to content

Isolate GCC specific code #1505

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

Merged

Conversation

t-harvey
Copy link

Folks,
This is the second half of our attempt to enable Jerryscript for compilers other than GCC -- in this case, the TI compilers.

Copied from the commit message:

These changes are designed to enable the TI compilers to compile
Jerryscript.  The changes include:

CMakeLists.txt: we added conditionals around GCC-specific flags, added
support for TI flags, and removed the always-on debugging flag (-g)

/toolchain_mcu_tim4f.cmake: new toolchain file uses TI-specific parameters

jerry-api.h: the sys/types.h file was #include'd but never used, so we
removed it

jrt-types.h: ditto

jerry-port-default-date.c: the TI toolchain doesn't include
sys/time.h, so we guarded uses of the package

...thanks for reviewing these changes!
Tim

@@ -88,10 +88,25 @@ macro(jerry_add_compile_flags)
jerry_add_flags(CMAKE_C_FLAGS ${ARGV})
endmacro()

# SHOULD THIS BE, SAY, AT THE TOP OF THE FILE?
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this condition is necessary, maybe you should use CMAKE_COMPILER_IS_GNUCC to check if the compiler is a variant of gcc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working off of the cmake documentation -- https://cmake.org/cmake/help/v3.0/variable/CMAKE_LANG_COMPILER_ID.html -- is there a better/conventional way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's correct in both cases, I was wondering how to avoid this USING_GCC variable, since the CMAKE_COMPILER_IS_GNUCC is also true when CMAKE_C_COMPILER_ID is
"GNU", but I think you're right and using directly the CMAKE_C_COMPILER_ID to determine the GNU compiler is closely aligned with the conventional way.


if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(USING_CLANG 1)
set(USING_GCC_OR_CLANG 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the USING_GCC_OR_CLANG variable is unnecessary, instead you should check if the compiler is a variant of gcc or a Clang compiler.

@@ -102,22 +117,28 @@ macro(jerry_add_link_flags)
endmacro()

# build mode specific compile/link flags
if(USE_GCC)
set(CMAKE_C_FLAGS_RELEASE "-Os")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also specify this optimization level for Clang.


# Architecture-specific compile/link flags
jerry_add_compile_flags(${FLAGS_COMMON_ARCH})
jerry_add_flags(CMAKE_EXE_LINKER_FLAGS ${FLAGS_COMMON_ARCH})

# Enable static build
if(ENABLE_STATIC_LINK)
jerry_add_link_flags("-static")
if (USING_GCC_OR_CLANG)
Copy link
Contributor

@robertsipka robertsipka Dec 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the static linking isn't supported with TI compilers you should set this value to OFF and send a message that It has been disabled, because the compiler doesn't support it and this condition will be needless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually the other way: we only support static linking. :-)

This means that we don't have a "-static" flag, which is why it's behind the GCC/Clang conditional...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see :). If the ENABLE STATIC_LINK is off, please set its value to ON and write a STATUS message that the ENABLE_STATIC_LINK has been enabled.

jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
if(CMAKE_COMPILER_IS_GNUCC)
if (USING_GCC_OR_CLANG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right -- I missed this one... The TI compiler flag is slightly different, and I've added it, here.

@robertsipka
Copy link
Contributor

Thank you for doing this patch, I think this patch is a step in the right direction to build JerryScript with other compilers, like TI compilers.


# Debug information
jerry_add_compile_flags(-g)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you add this flag somewhere else?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't; -- I wasn't confident in this change. :-)

I understand that -g was put in as a default variable b/c of an earlier bug in the code (maybe in jerry-main?...my memory doesn't get better as I age :-) -- and I know that interim fixes have made setting -g as the default unnecessary.

I like the flow that has the user set the cmake variables CMAKE__<DEBUG|RELEASE> to include/exclude settings -- this, I think, matches user expectations...

...but, as with all of these, I'll gladly make an argument and start a discussion, but I've got no ego in this: if I'm wrong here, I'll happily fix it (if we put -g back as an always-set flag, does it go back here, or, if not, where?)...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit, it's not necessary to compiling a release build with debug flags.

@@ -313,7 +313,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);

/* 1. */
ecma_extended_property_ref_t ext_property_ref;
ecma_extended_property_ref_t ext_property_ref = {0,0};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow, my push caused Travis to report that this variable could be used before being initialized, so I just added the obvious initialization...

@@ -313,7 +313,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);

/* 1. */
ecma_extended_property_ref_t ext_property_ref = {0,0};
ecma_extended_property_ref_t ext_property_ref = {{0},0};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and now Travis says this is wrong:

./jerry-core/ecma/operations/ecma-objects-general.c:316: error: brace should be placed on a separate line

...I assume that this is a style checker, objecting to the braces? This code, however, looks like the right way to write it: am I not following a standard, or is there a bug in the style-checking code?

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 46c792d to 8b8f34c Compare January 4, 2017 16:33
@zherczeg
Copy link
Member

zherczeg commented Jan 5, 2017

Please rebase this patch to master.

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch 2 times, most recently from 0c99599 to 98b3700 Compare January 5, 2017 23:46
@t-harvey
Copy link
Author

t-harvey commented Jan 5, 2017

Robert,
In re ENABLE_STATIC_LINK -- so I played with a number of error messages, and I never got one I liked: they either fell in unexpected places (so the user isn't looking for them), or they interrupted other output (they just got in the way).

I compromised by hanging a comment off of the current printout of flags:

...normally, you'd see this:

-- ENABLE_ALL_IN_ONE OFF
-- ENABLE_LTO ON
-- ENABLE_STATIC_LINK ON
-- ENABLE_STRIP ON
-- JERRY_CMDLINE OFF

...if the compiler doesn't do dynamic linking, you get this:

-- ENABLE_ALL_IN_ONE OFF
-- ENABLE_LTO ON
-- ENABLE_STATIC_LINK ON (ONLY OPTION FOR THIS COMPILER)
-- ENABLE_STRIP ON
-- JERRY_CMDLINE OFF

...is this okay?

I've squashed all of the commits, so if everything looks good, this is ready for pulling.

@zherczeg
Copy link
Member

zherczeg commented Jan 6, 2017

The #1483 should be landed first since this PR depends on that.

@robertsipka
Copy link
Contributor

robertsipka commented Jan 6, 2017

@t-harvey : Yes, this message form is perfect, thanks.
I would not set the USING_GCC_OR_CLANG variable. Could you use "USING_GCC OR USING_CLANG" in the affected conditions instead of "USING_GCC_OR_CLANG"? LGTM (informally) after these changes.

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 98b3700 to 2b68446 Compare January 6, 2017 14:59
@LaszloLango
Copy link
Contributor

@t-harvey, please rebase to the current master.

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 2b68446 to 8c00f15 Compare January 9, 2017 20:05
if(USING_GCC OR USING_CLANG)
set(CMAKE_C_FLAGS_RELEASE "-Os")
endif()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed anymore, see #1513.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed... I had a little trouble getting the rebase done (and I had a failure in the runtime tests, which was weird, as it went away over the course of the afternoon :-), but it should be ready to go now...

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 8c00f15 to d1de4e8 Compare January 9, 2017 21:36
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line at the end of the file

@@ -313,7 +313,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);

/* 1. */
ecma_extended_property_ref_t ext_property_ref;
ecma_extended_property_ref_t ext_property_ref = {{0},0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Vera++ rule is not clever enough to recognize this. But the correct style would be { { 0 }, 0 }
I suggest to use a define to workaround this problem.

diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h
index 99b6da3..fa87e91 100644
--- a/jerry-core/ecma/base/ecma-globals.h
+++ b/jerry-core/ecma/base/ecma-globals.h
@@ -468,6 +468,11 @@ typedef struct
 #define ECMA_PROPERTY_SEARCH_DEPTH_LIMIT 128
 
 /**
+ * Empty extended property reference
+ */
+#define ECMA_EMPTY_EXTENDED_PROPERTY_REFERENCE { { 0 }, 0 }
+
+/**
  * Property reference. It contains the value pointer
  * for real, and the value itself for virtual properties.
  */
diff --git a/jerry-core/ecma/operations/ecma-objects-general.c b/jerry-core/ecma/operations/ecma-objects-general.c
index c24f356..5b479b2 100644
--- a/jerry-core/ecma/operations/ecma-objects-general.c
+++ b/jerry-core/ecma/operations/ecma-objects-general.c
@@ -313,7 +313,7 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
   JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);
 
   /* 1. */
-  ecma_extended_property_ref_t ext_property_ref;
+  ecma_extended_property_ref_t ext_property_ref = ECMA_EMPTY_EXTENDED_PROPERTY_REFERENCE;
   ecma_property_t current_prop;
 
   current_prop = ecma_op_object_get_own_property (object_p,

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch 2 times, most recently from 839e91f to 592ebc3 Compare January 10, 2017 15:33
Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zherczeg
Copy link
Member

zherczeg commented Jan 13, 2017

The #1483 should be landed first since this PR depends on that.

Just to not forget about it.

@tilmannOSG tilmannOSG changed the title Isolate gcc specific code Isolate GCC specific code Jan 13, 2017
Copy link

@tilmannOSG tilmannOSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor style nitpicks :)
Thanks for working on this! Great to see that JerryScript can now be built for TI devices :)


if(USING_TI)
# if using a compiler that _only_ does static linking, inform the user
# of the discrepancy in settings

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start the comment with an upper case letter and end with a full stop :)

@@ -313,7 +313,9 @@ ecma_op_general_object_define_own_property (ecma_object_t *object_p, /**< the ob
JERRY_ASSERT (property_desc_p->is_writable_defined || !property_desc_p->is_writable);

/* 1. */
ecma_extended_property_ref_t ext_property_ref;
/* this #def just gets around the syntax/style checker...*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start the comment with an upper case letter as well :)

@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 592ebc3 to 502cdf0 Compare January 13, 2017 21:56
@tilmannOSG
Copy link

@t-harvey Thanks for the update, this PR is now ready to be merged (can be merged once #1483 has landed).

@LaszloLango
Copy link
Contributor

@t-harvey, #1483 is merged. Please rebase, so we can merge this PR too.

Jerryscript.  The changes include:

CMakeLists.txt: we added conditionals around GCC-specific flags, added
support for TI flags, and removed the always-on debugging flag (-g)

/toolchain_mcu_tim4f.cmake: new toolchain file uses TI-specific parameters

jerry-api.h: the sys/types.h file was #include'd but never used, so we
removed it

jrt-types.h: ditto

jerry-port-default-date.c: the TI toolchain doesn't include
sys/time.h, so we guarded uses of the package

ecma-objects-general.c: added initialization that Travis (the
auto-checking tool) required

JerryScript-DCO-1.0-Signed-off-by: Timothy Harvey [email protected]
@t-harvey t-harvey force-pushed the isolate_gcc_specific_code branch from 5ad0ea7 to ab46d13 Compare January 23, 2017 20:09
@tilmannOSG tilmannOSG merged commit f88d1a4 into jerryscript-project:master Jan 24, 2017
akosthekiss added a commit to akosthekiss/jerryscript that referenced this pull request Apr 22, 2017
PR jerryscript-project#1505 added support for TI compiler. It explicitly added a
message to notify the user that static linking is forced. PR jerryscript-project#1755
added a more generic approach to signal such forced settings and
adapted the TI-specific static linking notification to this
approach. However, it turned out that TI forcibly changed another
setting, too: it disabled release binary stripping, but without
notification. This patch fixes this by moving the setting override
to a consistent place and adding a notification.

PR jerryscript-project#1505 also added some source code changes, most importantly a
complex struct initialization for a variable in
`ecma-objects-general.c`. However, that initialization was coded
as a macro to trick the style checker. This patch gets rid of that
macro and uses proper C99 struct initializer with designators.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
akosthekiss added a commit to akosthekiss/jerryscript that referenced this pull request Apr 24, 2017
PR jerryscript-project#1505 added support for TI compiler. It explicitly added a
message to notify the user that static linking is forced. PR jerryscript-project#1755
added a more generic approach to signal such forced settings and
adapted the TI-specific static linking notification to this
approach. However, it turned out that TI forcibly changed another
setting, too: it disabled release binary stripping, but without
notification. This patch fixes this by moving the setting override
to a consistent place and adding a notification.

PR jerryscript-project#1505 also added some source code changes, most importantly a
complex struct initialization for a variable in
`ecma-objects-general.c`. However, that initialization was coded
as a macro to trick the style checker. This patch gets rid of that
macro and uses proper C99 struct initializer with designators.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
akosthekiss added a commit that referenced this pull request Apr 26, 2017
PR #1505 added support for TI compiler. It explicitly added a
message to notify the user that static linking is forced. PR #1755
added a more generic approach to signal such forced settings and
adapted the TI-specific static linking notification to this
approach. However, it turned out that TI forcibly changed another
setting, too: it disabled release binary stripping, but without
notification. This patch fixes this by moving the setting override
to a consistent place and adding a notification.

PR #1505 also added some source code changes, most importantly a
complex struct initialization for a variable in
`ecma-objects-general.c`. However, that initialization was coded
as a macro to trick the style checker. This patch gets rid of that
macro and uses proper C99 struct initializer with designators.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
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

Successfully merging this pull request may close these issues.

5 participants