A dam or barrier around the periphery of a die in a flip-chip package changes the shape of the underfill to reduce stress resulting from edge effects. The dam can include a treated region of a substrate having an affinity to an underfill material. The treated region causes liquid underfill material to bead, thereby controlling the wetting angle of the underfill material and shaping the underfill to eliminate sources of stress such as underfill fillet regions that are subject to significant shrinkage. The dammed underfill additionally avoids or reduces the extent of areas having thermal coefficients of expansion that differ from the optimal level because of low filler particle concentration.