Skip to content

Commit

Permalink
ARM32 bit fixes, for 64bit printf format specifier (sonic-net#490)
Browse files Browse the repository at this point in the history
* ARM32 bit fixes, for 64bit printf format specifier

Signed-off-by: Antony Rheneus <arheneus@marvell.com>

* [Warning] -Wlong-long is valid for ULL const in Arm32bit
pointer cast align warnings

Signed-off-by: Antony Rheneus <arheneus@marvell.com>

* Warning fixes for using ULL and pointer type casting in 32 bit arch

Signed-off-by: Antony Rheneus <arheneus@marvell.com>

* deserialized value didnt match, reverting the warning fix

Signed-off-by: Antony Rheneus <arheneus@marvell.com>

* Fix for deserialized value not matching after warning changes

Signed-off-by: Antony Rheneus <arheneus@marvell.com>

* Put back the reverted fix

Signed-off-by: Antony Rheneus <arheneus@marvell.com>
  • Loading branch information
antony-rheneus authored and lguohan committed Aug 8, 2019
1 parent 70490b4 commit 6bc64ee
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 61 deletions.
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ CFLAGS_COMMON+=" -Wimport"
CFLAGS_COMMON+=" -Winit-self"
CFLAGS_COMMON+=" -Winline"
CFLAGS_COMMON+=" -Winvalid-pch"
CFLAGS_COMMON+=" -Wlong-long"
CFLAGS_COMMON+=" -Wmissing-field-initializers"
CFLAGS_COMMON+=" -Wmissing-format-attribute"
CFLAGS_COMMON+=" -Wmissing-include-dirs"
Expand All @@ -95,7 +94,6 @@ CFLAGS_COMMON+=" -Wvariadic-macros"
CFLAGS_COMMON+=" -Wwrite-strings"
CFLAGS_COMMON+=" -Wno-switch-default"
CFLAGS_COMMON+=" -Wconversion"
CFLAGS_COMMON+=" -Wlong-long"

AC_SUBST(CFLAGS_COMMON)

Expand Down
1 change: 0 additions & 1 deletion meta/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ WARN = \
-Winit-self \
-Winline \
-Winvalid-pch \
-Wlong-long \
-Wmissing-field-initializers \
-Wmissing-format-attribute \
-Wmissing-include-dirs \
Expand Down
2 changes: 1 addition & 1 deletion meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ void sai_deserialize_pointer(
{
SWSS_LOG_ENTER();

sai_deserialize_number(s, (uint64_t&)ptr, true);
sai_deserialize_number(s, (uintptr_t &)ptr, true);
}

void sai_deserialize_ip_address(
Expand Down
11 changes: 6 additions & 5 deletions meta/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "sai_extra.h"
#include "sai_serialize.h"

#include <inttypes.h>
#include <string.h>
#include <arpa/inet.h>

Expand Down Expand Up @@ -42,7 +43,7 @@ sai_object_type_t sai_object_type_query(
if ((objecttype <= SAI_OBJECT_TYPE_NULL) ||
(objecttype >= SAI_OBJECT_TYPE_EXTENSIONS_MAX))
{
SWSS_LOG_THROW("invalid oid 0x%lx", oid);
SWSS_LOG_THROW("invalid oid 0x%" PRIx64, oid);
}

return objecttype;
Expand Down Expand Up @@ -121,7 +122,7 @@ sai_object_id_t create_dummy_object_id(

sai_object_id_t oid = construct_object_id(object_type, sw_index, vid_index++);

SWSS_LOG_DEBUG("created oid 0x%lx", oid);
SWSS_LOG_DEBUG("created oid 0x%" PRIx64, oid);

return oid;
}
Expand Down Expand Up @@ -3077,7 +3078,7 @@ void test_acl_entry_field_and_action()

list[0] = insert_dummy_object(SAI_OBJECT_TYPE_QUEUE,switch_id);

SWSS_LOG_NOTICE("0x%lx", list[0]);
SWSS_LOG_NOTICE("0x%" PRIx64, list[0]);

attr.value.aclaction.parameter.objlist.count = 1;
attr.value.aclaction.parameter.objlist.list = list;
Expand Down Expand Up @@ -3426,7 +3427,7 @@ void test_serialize_uint64()
s = sai_serialize_attr_value(*meta, attr);

char buf[32];
sprintf(buf, "%lu", attr.value.u64);
sprintf(buf, "%" PRIu64, attr.value.u64);

ASSERT_TRUE(s, std::string(buf));

Expand Down Expand Up @@ -4016,7 +4017,7 @@ std::string serialize_number(
{
char buf[32];

snprintf(buf, sizeof(buf), "0x%lx", (uint64_t)number);
snprintf(buf, sizeof(buf), "0x%" PRIx64, (uint64_t)number);

return buf;
}
Expand Down
3 changes: 2 additions & 1 deletion saidump/saidump.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <inttypes.h>
#include <string>
#include <set>
#include <sstream>
Expand Down Expand Up @@ -133,7 +134,7 @@ const TableMap* get_table_map(sai_object_id_t object_id)

if (it == g_oid_map.end())
{
SWSS_LOG_THROW("unable to find oid 0x%lx in oid map", object_id);
SWSS_LOG_THROW("unable to find oid 0x%" PRIx64 " in oid map", object_id);
}

return it->second;
Expand Down
3 changes: 2 additions & 1 deletion saiplayer/saiplayer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <inttypes.h>
#include <getopt.h>
#include <unistd.h>

Expand Down Expand Up @@ -354,7 +355,7 @@ void match_redis_with_rec(

if (oid != redis_to_local[get_oid])
{
SWSS_LOG_THROW("match failed, oid order is mismatch :( oid 0x%lx get_oid 0x%lx second 0x%lx",
SWSS_LOG_THROW("match failed, oid order is mismatch :( oid 0x%" PRIx64 " get_oid 0x%" PRIx64 " second 0x%" PRIx64,
oid,
get_oid,
redis_to_local[get_oid]);
Expand Down
31 changes: 16 additions & 15 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "sairedis.h"
#include "syncd_flex_counter.h"
#include "swss/tokenize.h"
#include <inttypes.h>
#include <limits.h>

#include "swss/warm_restart.h"
Expand Down Expand Up @@ -220,7 +221,7 @@ sai_object_type_t redis_sai_object_type_query(

if (!sai_metadata_is_object_type_valid(ot))
{
SWSS_LOG_THROW("invalid object id 0x%lx", object_id);
SWSS_LOG_THROW("invalid object id 0x%" PRIx64, object_id);
}

return ot;
Expand Down Expand Up @@ -257,7 +258,7 @@ sai_object_id_t redis_sai_switch_id_query(

if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("invalid object type of oid 0x%lx", oid);
SWSS_LOG_THROW("invalid object type of oid 0x%" PRIx64, oid);
}

if (object_type == SAI_OBJECT_TYPE_SWITCH)
Expand Down Expand Up @@ -316,7 +317,7 @@ sai_object_id_t redis_create_virtual_object_id(

auto info = sai_metadata_get_object_type_info(object_type);

SWSS_LOG_DEBUG("created virtual object id 0x%lx for object type %s",
SWSS_LOG_DEBUG("created virtual object id 0x%" PRIx64 " for object type %s",
vid,
info->objecttypename);

Expand Down Expand Up @@ -393,18 +394,18 @@ sai_object_id_t translate_rid_to_vid(

sai_deserialize_object_id(str_vid, vid);

SWSS_LOG_DEBUG("translated RID 0x%lx to VID 0x%lx", rid, vid);
SWSS_LOG_DEBUG("translated RID 0x%" PRIx64 " to VID 0x%" PRIx64, rid, vid);

return vid;
}

SWSS_LOG_DEBUG("spotted new RID 0x%lx", rid);
SWSS_LOG_DEBUG("spotted new RID 0x%" PRIx64, rid);

sai_object_type_t object_type = sai_object_type_query(rid);

if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_THROW("sai_object_type_query returned NULL type for RID 0x%lx", rid);
SWSS_LOG_THROW("sai_object_type_query returned NULL type for RID 0x%" PRIx64, rid);
}

if (object_type == SAI_OBJECT_TYPE_SWITCH)
Expand All @@ -414,12 +415,12 @@ sai_object_id_t translate_rid_to_vid(
* created switch, so we should never get here.
*/

SWSS_LOG_THROW("RID 0x%lx is switch object, but not in local or redis db, bug!", rid);
SWSS_LOG_THROW("RID 0x%" PRIx64 " is switch object, but not in local or redis db, bug!", rid);
}

vid = redis_create_virtual_object_id(switch_vid, object_type);

SWSS_LOG_DEBUG("translated RID 0x%lx to VID 0x%lx", rid, vid);
SWSS_LOG_DEBUG("translated RID 0x%" PRIx64 " to VID 0x%" PRIx64, rid, vid);

std::string str_vid = sai_serialize_object_id(vid);

Expand Down Expand Up @@ -613,7 +614,7 @@ sai_object_id_t translate_vid_to_rid(
SWSS_LOG_THROW("can't get RID in init view mode - don't query created objects");
}

SWSS_LOG_THROW("unable to get RID for VID: 0x%lx", vid);
SWSS_LOG_THROW("unable to get RID for VID: 0x%" PRIx64, vid);
}

str_rid = *prid;
Expand All @@ -629,7 +630,7 @@ sai_object_id_t translate_vid_to_rid(

local_vid_to_rid[vid] = rid;

SWSS_LOG_DEBUG("translated VID 0x%lx to RID 0x%lx", vid, rid);
SWSS_LOG_DEBUG("translated VID 0x%" PRIx64 " to RID 0x%" PRIx64, vid, rid);

return rid;
}
Expand Down Expand Up @@ -1258,7 +1259,7 @@ sai_status_t handle_generic(

if (switch_id == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_THROW("invalid switch_id translated from VID 0x%lx", object_id);
SWSS_LOG_THROW("invalid switch_id translated from VID 0x%" PRIx64, object_id);
}

if (object_type != SAI_OBJECT_TYPE_SWITCH)
Expand Down Expand Up @@ -1319,7 +1320,7 @@ sai_status_t handle_generic(
{
on_switch_create(switch_id);
gSwitchId = real_object_id;
SWSS_LOG_NOTICE("Initialize gSwitchId with ID = 0x%lx", gSwitchId);
SWSS_LOG_NOTICE("Initialize gSwitchId with ID = 0x%" PRIx64, gSwitchId);
}
}

Expand Down Expand Up @@ -2130,7 +2131,7 @@ void on_switch_create_in_init_view(

#ifdef SAITHRIFT
gSwitchId = switch_rid;
SWSS_LOG_NOTICE("Initialize gSwitchId with ID = 0x%lx", gSwitchId);
SWSS_LOG_NOTICE("Initialize gSwitchId with ID = 0x%" PRIx64, gSwitchId);
#endif

/*
Expand Down Expand Up @@ -4142,7 +4143,7 @@ int syncd_main(int argc, char **argv)
}
}

SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%lx", gSwitchId);
SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%" PRIx64, gSwitchId);

#ifdef SAI_SUPPORT_UNINIT_DATA_PLANE_ON_REMOVAL

Expand Down Expand Up @@ -4182,7 +4183,7 @@ int syncd_main(int argc, char **argv)

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=%s", gSwitchId,
SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%" PRIx64 " status=%s", gSwitchId,
sai_serialize_status(status).c_str());
}

Expand Down
19 changes: 10 additions & 9 deletions syncd/syncd_applyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "swss/logger.h"
#include "swss/dbconnector.h"

#include <inttypes.h>
#include <algorithm>
#include <list>

Expand Down Expand Up @@ -1434,7 +1435,7 @@ class AsicView

v.insert(v.begin() + index, op);

SWSS_LOG_INFO("move 0x%lx all way up (not in map): %s to index: %zu", op.vid,
SWSS_LOG_INFO("move 0x%" PRIx64 " all way up (not in map): %s to index: %zu", op.vid,
sai_serialize_object_type(redis_sai_object_type_query(op.vid)).c_str(),index);

index++;
Expand Down Expand Up @@ -1503,7 +1504,7 @@ class AsicView

v.insert(v.begin() + index, op);

SWSS_LOG_INFO("move 0x%lx in the middle up: %s (last: %zu curr: %zu)", op.vid,
SWSS_LOG_INFO("move 0x%" PRIx64 " in the middle up: %s (last: %zu curr: %zu)", op.vid,
sai_serialize_object_type(redis_sai_object_type_query(op.vid)).c_str(), lastOpIdDecRefIndex, index);

index++;
Expand Down Expand Up @@ -5736,7 +5737,7 @@ std::shared_ptr<SaiAttr> getSaiAttrFromDefaultValue(

if (tg == currentView.ridToVid.end())
{
SWSS_LOG_THROW("default trap group RID 0x%lx doesn't exist in current view", currentView.defaultTrapGroupRid);
SWSS_LOG_THROW("default trap group RID 0x%" PRIx64 " doesn't exist in current view", currentView.defaultTrapGroupRid);
}

sai_attribute_t at;
Expand Down Expand Up @@ -7290,14 +7291,14 @@ void checkMap(
sai_object_id_t v = it.second;

if (firstV2R.find(v) == firstV2R.end())
SWSS_LOG_ERROR("%s (0x%lx:0x%lx) is missing from %s", firstR2Vname, r, v, firstV2Rname);
SWSS_LOG_ERROR("%s (0x%" PRIx64 ":0x%" PRIx64 ") is missing from %s", firstR2Vname, r, v, firstV2Rname);
else if (firstV2R.at(v) != r)
SWSS_LOG_ERROR("mismatch on %s (0x%lx:0x%lx) vs %s (0x%lx:0x%lx)", firstR2Vname, r, v, firstV2Rname, v, firstV2R.at(v));
SWSS_LOG_ERROR("mismatch on %s (0x%" PRIx64 ":0x%" PRIx64 ") vs %s (0x%" PRIx64 ":0x%" PRIx64 ")", firstR2Vname, r, v, firstV2Rname, v, firstV2R.at(v));

if (secondR2V.find(r) == secondR2V.end())
SWSS_LOG_ERROR("%s (0x%lx:0x%lx) is missing from %s", firstR2Vname, r, v, secondR2Vname);
SWSS_LOG_ERROR("%s (0x%" PRIx64 ":0x%" PRIx64 ") is missing from %s", firstR2Vname, r, v, secondR2Vname);
else if (secondV2R.find(secondR2V.at(r)) == secondV2R.end())
SWSS_LOG_ERROR("%s (0x%lx:0x%lx) is missing from %s", firstR2Vname, r, secondR2V.at(r), secondV2Rname);
SWSS_LOG_ERROR("%s (0x%" PRIx64 ":0x%" PRIx64 ") is missing from %s", firstR2Vname, r, secondR2V.at(r), secondV2Rname);
}
}

Expand Down Expand Up @@ -7360,7 +7361,7 @@ void createPreMatchMapForObject(
if (cur.oOids.at(cVid)->getObjectType() != tmp.oOids.at(tVid)->getObjectType())
continue;

SWSS_LOG_INFO("inserting pre match entry for %s:%s: 0x%lx (tmp) -> 0x%lx (cur)",
SWSS_LOG_INFO("inserting pre match entry for %s:%s: 0x%" PRIx64 " (tmp) -> 0x%" PRIx64 " (cur)",
tObj->str_object_id.c_str(),
cAttr->getAttrMetadata()->attridname,
tVid,
Expand Down Expand Up @@ -7742,7 +7743,7 @@ sai_object_id_t asic_translate_vid_to_rid(

sai_object_id_t rid = currentIt->second;

SWSS_LOG_INFO("translated VID 0x%lx to RID 0x%lx", vid, rid);
SWSS_LOG_INFO("translated VID 0x%" PRIx64 " to RID 0x%" PRIx64, vid, rid);

return rid;
}
Expand Down
Loading

0 comments on commit 6bc64ee

Please sign in to comment.