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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,35 @@ if("${PLATFORM}" STREQUAL "DARWIN")
set(ENABLE_STATIC_LINK "OFF")
endif()


if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(USING_GCC 1)
endif()

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(USING_CLANG 1)
endif()

if(CMAKE_C_COMPILER_ID MATCHES "TI")
set(USING_TI 1)
endif()

# Status messages
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
message(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE})
message(STATUS "ENABLE_LTO " ${ENABLE_LTO})
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK})

if(USING_TI)
# If using a compiler that _only_ does static linking, inform the user
# of the discrepancy in settings.
set(ENABLE_STATIC_LINK "ON")
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK} " (ONLY OPTION FOR THIS COMPILER)")
else()
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK})
endif()

message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP})
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE})
message(STATUS "JERRY_CMDLINE_MINIMAL " ${JERRY_CMDLINE_MINIMAL})
Expand Down Expand Up @@ -91,7 +113,7 @@ endmacro()
macro(jerry_add_compile_warnings)
foreach(_warning ${ARGV})
jerry_add_compile_flags(-W${_warning})
if(CMAKE_COMPILER_IS_GNUCC)
if(USING_GCC)
jerry_add_compile_flags(-Werror=${_warning})
endif()
endforeach()
Expand All @@ -107,21 +129,28 @@ 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 USING_CLANG)
jerry_add_link_flags("-static")
endif()
endif()

# LTO
if(ENABLE_LTO)
jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
if(CMAKE_COMPILER_IS_GNUCC)
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
endif()
if(USING_GCC)
if(NOT "${PLATFORM}" STREQUAL "DARWIN")
jerry_add_compile_flags(-fno-fat-lto-objects)
endif()
# Use gcc-ar and gcc-ranlib to support LTO
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
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.

endif()
if(USING_TI)
jerry_add_link_flags(-lto)
endif()
endif()

# Define _BSD_SOURCE and _DEFAULT_SOURCE if we use default port and compiler default libc
Expand All @@ -130,7 +159,9 @@ if(${PORT_DIR} STREQUAL "${CMAKE_SOURCE_DIR}/targets/default" AND NOT JERRY_LIBC
endif()

# Compiler / Linker flags
jerry_add_compile_flags(-fno-builtin)
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-fno-builtin)
endif()
if(("${PLATFORM}" STREQUAL "DARWIN"))
jerry_add_link_flags(-lSystem)
else()
Expand All @@ -143,17 +174,18 @@ if(JERRY_LIBC)
endif()

# Turn off stack protector
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-fno-stack-protector)
endif()

# Debug information
jerry_add_compile_flags(-g)

jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
if (USING_GCC OR USING_CLANG)
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations)
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
endif()

if(CMAKE_COMPILER_IS_GNUCC)
if(USING_GCC)
jerry_add_compile_warnings(logical-op)
else()
elseif(USING_CLANG)
jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline)
endif()

Expand All @@ -162,11 +194,17 @@ if(JERRY_LIBC)
endif()

# C
jerry_add_compile_flags(-std=c99 -pedantic)
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-std=c99 -pedantic)
elseif(USING_TI)
jerry_add_compile_flags(--c99)
endif()

# Strip binary
if(ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
jerry_add_link_flags(-s)
if (USING_GCC OR USING_CLANG)
jerry_add_link_flags(-s)
endif()
endif()

# External compiler & linker flags
Expand Down
33 changes: 33 additions & 0 deletions cmake/toolchain_mcu_tim4f.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include(CMakeForceCompiler)

set(CMAKE_SYSTEM_NAME MCU)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_SYSTEM_VERSION TIM4F)

set(FLAGS_COMMON_ARCH --little_endian --silicon_version=7M4 --float_support=FPv4SPD16)

CMAKE_FORCE_C_COMPILER(armcl TI)

SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-o4 -mf0 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE_INIT "-o4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-o2 -g")

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")
4 changes: 3 additions & 1 deletion jerry-core/ecma/operations/ecma-objects-general.c
Original file line number Diff line number Diff line change
Expand Up @@ -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... */
#define extended_property_ref_initialization { { 0 } , 0 }
ecma_extended_property_ref_t ext_property_ref = extended_property_ref_initialization;
ecma_property_t current_prop;

current_prop = ecma_op_object_get_own_property (object_p,
Expand Down
1 change: 0 additions & 1 deletion jerry-core/jerry-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C"
Expand Down
1 change: 0 additions & 1 deletion jerry-core/jrt/jrt-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

#endif /* !JRT_TYPES_H */
12 changes: 11 additions & 1 deletion targets/default/jerry-port-default-date.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* limitations under the License.
*/

#ifdef __GNUC__
#include <sys/time.h>
#endif

#include "jerry-port.h"
#include "jerry-port-default.h"
Expand All @@ -23,6 +25,7 @@
*/
bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
{
#ifdef __GNUC__
struct timeval tv;
struct timezone tz;

Expand All @@ -39,19 +42,26 @@ bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p)
tz_p->daylight_saving_time = tz.tz_dsttime > 0 ? 1 : 0;

return true;
#else /* !__GNUC__ */
return false;
#endif /* __GNUC__ */
} /* jerry_port_get_time_zone */

/**
* Default implementation of jerry_port_get_current_time.
*/
double jerry_port_get_current_time ()
{
#ifdef __GNUC__
struct timeval tv;

if (gettimeofday (&tv, NULL) != 0)
{
return 0;
return 0.0;
}

return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
#else /* __!GNUC__ */
return 0.0;
#endif /* __GNUC__ */
} /* jerry_port_get_current_time */