"accumulation; ball," 1620s, from Latin glomerationem (nominative glomeratio), noun of action from past-participle stem of glomerare "to wind or form into a ball, roll together, collect," from glomus "ball of yarn, ball-shaped mass," from Proto-Italic *glemos-, from PIE *glem- or *glom-, perhaps originally "ball," but the reconstruction is uncertain (see glebe).
Sense of "darkness, obscurity" is first recorded 1629 in Milton's poetry; that of "melancholy, dejection, cloudiness or cheerless heaviness of mind" is from 1744; but gloomy with a corresponding sense is attested from 1580s.
late 14c., "soil of the earth; cultivated land;" also "a piece of land forming part of a clergyman's benefice," from Old French glebe, from Latin gleba, glaeba "clod, lump of earth," possibly from a PIE *glem- or *glom-, which might mean "contain, embrace" or "ball," or might be two different roots. Possible cognates include Old English clamm "a tie, fetter;" Old High German klamma "trap, gorge;" Old Irish glomar "gag, curb;" Latin globus "sphere," gleba, glaeba "clod, lump of earth;" Old English clyppan "to embrace;" Lithuanian glėbys "armful," globti "to embrace, support."
bivalve mollusk, c. 1500 (in clam-shell), originally Scottish, apparently a particular use of Middle English clam "pincers, vice, clamp" (late 14c.), from Old English clamm "bond, fetter, grip, grasp," from Proto-Germanic *klam- "to press or squeeze together" (source also of Old High German klamma "cramp, fetter, constriction," German Klamm "a constriction"), possibly from a PIE *glem- or *glom- "contain, embrace" (see glebe).
If this is right then the original reference is to the shell. Clam-chowder attested from 1822. To be happy as a clam is from 1833, but the earliest uses do not elaborate on the notion behind it, unless it be self-containment.